I'm using rdpcap
function of Scapy to read a PCAP file.
I also use the module described in a link to HTTP support in Scapy which is needed in my case, as I have to retrieve all the HTTP requests and responses and their related packets.
I noticed that parsing a large PCAP file the rdpcap
function takes too much time to read it.
Is there a solution to read a pcap
file faster?
While I agree the load time is longer than one might expect, it is likely because the file is being parsed to generate an array of highly composed objects. What I've had to do was use
editcap
to chop up the packet captures to make reading them a bit easier. For example:Please note: a full explanation of the switches of this command is available here.
Also, the
-F libpcap
part seemed to be necessary (at least for me) to get scapy'spcap
function able to parse the file. (This is supposed to be the default pcap file output format, but this was not the case for me, for whatever reason. You can verify the file type of your input and output files withcapinfos
(e.g., simply entercapinfos your_capture.pcap
).Both
capinfos
andeditcap
are available with the WireShark distribution.Scapy has another method
sniff
which you can use to read the pcap files too:rdpcap
loads the entire pcap file to the memory. Hence it uses a lot of memory and as you said its slow. Whilesniff
reads one packet at a time and passes it to the providedprn
function. Thatstore=0
parameter ensures that the packet is deleted from memory as soon as it is processed.