please i am trying to analyse a pcap file in python using dpkt. I am having troubles with the code that 1) counts the number of TCP flows in the pcap file 2) counts the number of UDP flows in the pcap file 3) counts the number of unique IP addresses 4) calculate the total number of packets per flow 5) calculate the average packet size per flow 6) calculate the duration of each flow. From my code above, i have not been able to achieve that.
I will appreciate it if anyone can help me with the python code for the above question. Thanks
this is what i have done so far
import dpkt
from functools import reduce
import socket
flows = {}
for ts,pkt in dpkt.pcap.Reader(open('tesst.pcap','rb')):
eth=dpkt.ethernet.Ethernet(pkt)
please i am trying to analyse a pcap file in python using dpkt. I am having troubles with the code that 1) counts the number of TCP flows in the pcap file 2) counts the number of UDP flows in the pcap file 3) counts the number of unique IP addresses 4) calculate the total number of packets per flow 5) calculate the average packet size per flow 6) calculate the duration of each flow. From my code above, i have not been able to achieve that. I will appreciate it if anyone can help me with the python code for the above question. Thanks
this is what i have done so far
import dpkt from functools import reduce import socket
flows = {}
for ts,pkt in dpkt.pcap.Reader(open('tesst.pcap','rb')): eth=dpkt.ethernet.Ethernet(pkt)
for k in flows.keys(): print(f'Data for flow: {k}:') bytes = reduce(lambda x, y: x+y, map(lambda e: e['byte_count'], flows[k])) print(f"Total Bytes: {bytes}")