Iterate all over tcp stream in pcap file with Scapy

Viewed 382

There is pcap file that contains some tcp stream , In wireshark there is filter tcp.stream eq 0 tcp.stream eq 1 ... to see only packet from specific tcp stream.

Is there any way with SCAPY to iterate all packets by tcp stream? I want to print all packet data by TCP stream like :

stream 0 : <packet 1> <packet 2>

stream 1 : <packet 3> <packet 4>

1 Answers

May be sniff function with parameter offline and session could satisfy your requirement.

from scapy.all import sniff, TCPSession
s = sniff(offline="h:/datasets/s1.pcap", session=TCPSession)
Related