I want to extract TCP streams of a PCAP file and obtain then analyze parameters of the streams, like iRTT, retransmission rate (something like "tcp.analysis" in Wireshark). I tried to used Pyshark to use Wireshark analysis but it was not available in fields and encountered 'Memory Error' with this code:
import pyshark
pkts = pyshark.FileCapture("test.pcapng", use_ek=False)
streams = {}
for pkt in pkts:
if 'tcp' not in pkt:
continue
if pkt.tcp.stream not in streams:
streams[pkt.tcp.stream] = list()
streams[pkt.tcp.stream].append(pkt)
I have no idea how can I use Scapy for my purpose. There are two challenges: Splitting TCP stream in an efficient way, and then calculate the streams' parameters.
What do you recommend?
I would start with tshark which I believe uses the same underlying code as wireshark.
Maybe start with something like
You can see the ack RTT in the output of this example, but I'm sure there are other fields besides ack_rtt that are available.
I don't see anything wrong with your python program though. Adding a section after your code to print out the packets works for me.
That gives me the following output: