If you are looking for a more responsive code, consider using PcapReader()
instead of rdpcap()
.
PcapReader()
creates a generator and loads a packet only when it is needed, as opposed to rdpcap()
which loads the entire trace into memory. PcapReader()
is, therefore, well-suited for a large trace that takes forever to load with rdpcap()
, or throws a MemoryError
because it's simply too large for your system.
Example code:
packets = PcapReader('filename.pcap')
for packet in packets:
mac_src = packet[Ether].src
mac_dst = packet[Ether].dst
...
Please refer to the PcapReader()
documentation for more information.
If you are only concerned about how long it takes to get the final output, then rdpcap()
might have an advantage over PcapReader()
, although I'm not sure about the magnitude of difference.