3 # disable IPv6 error message
5 logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
6 from scapy.all import *
7 logging.getLogger("scapy.runtime").setLevel(logging.WARN)
8 from pprint import pprint
11 # disable payload parsing (saves two seconds runtime^^)
17 # V discards the wirelen... ( http://stackoverflow.com/questions/21752576/whole-packet-length-scapy )
18 #for p in PcapReader('ex22.pcap'):
19 for pkt, (sec, usec, wirelen) in RawPcapReader('ex22.pcap'):
29 # print ("Src: %s (ether), Dest: %s (ip)" % (src, dst))
31 if (src,dst) in flowset:
32 i,o,l = flowset[(src,dst)]
34 l[wirelen] = l[wirelen]+1
37 flowset[(src,dst)] = (i+1,o,l)
38 elif (dst,src) in flowset:
39 i,o,l = flowset[(dst,src)]
41 l[wirelen] = l[wirelen]+1
44 flowset[(dst,src)] = (i,o+1,l)
46 flowset[(src,dst)] = (1,0,{wirelen: 1})
48 print("fcount: %d" % fcount)
53 for flow,counts in flowset.items():
54 if counts[0] > 200 or counts[1] > 200:
55 largeflows[flow] = (counts[0],counts[1])
58 filecount = filecount + 1
59 filename = "large_flow_%02d.pcap" % filecount
60 os.system('tshark -r ex22.pcap -w '+filename+' -F pcap "ip.src == '+flow[0]+' and ip.dst == '+flow[1]+' and frame.len == 42"')
62 filecount = filecount + 1
63 filename = "large_flow_%02d.pcap" % filecount
64 os.system('tshark -r ex22.pcap -w '+filename+' -F pcap "ip.src == '+flow[1]+' and ip.dst == '+flow[0]+' and frame.len == 42"')