with open('C:\\ips.txt', 'rb') as ip_file:
    txt = ip_file.read()
ip = re.findall('[0-9.]+[\\s]+[>][\\s0-9.]+', txt)
ip1 = ['>'.join(re.findall('[0-9.]+(?=[.])', i)) for i in ip]
packs = re.findall('(?<=length )[0-9]+', txt)
data = zip(ip1, packs)
d = defaultdict(list)
for k, v in data:
    d[k].append(v)
for i, j in list(d.items()):
    source, destination = i.split('>')[0], i.split('>')[1]
print('source: {0} destination: {1} total: {2}'.format(source, destination,
    sum(map(int, j))))
Open a file, read content, make content into a list using regex, then print list in python