Opening CAP file in Python using Scapy libraries raises and exception

774 views Asked by At

I have a cap file that I want to read and process using python, I used the Scapy library but when trying to read it using the rdpcap function it raises an exception.
CAP File
The full stacktrace:

Scapy_Exception                           Traceback (most recent call last)
<ipython-input-3-544e8f19828d> in <module>()
      1 file = '.....'
----> 2 packets = rdpcap(file)

1 frames
/usr/local/lib/python3.7/dist-packages/scapy/utils.py in rdpcap(filename, count)
   1115     # One day we should simplify this mess and use a much simpler
   1116     # layout that will actually be supported and properly dissected.
-> 1117     with PcapReader(filename) as fdesc:  # type: ignore
   1118         return fdesc.read_all(count=count)
   1119 

/usr/local/lib/python3.7/dist-packages/scapy/utils.py in __call__(cls, filename)
   1170                 pass
   1171 
-> 1172         raise Scapy_Exception("Not a supported capture file")
   1173 
   1174     @staticmethod

Scapy_Exception: Not a supported capture file

Note: I have managed to open the cap file in Wireshark and export it to CSV, but I want to know if there is a way to solve this since I have a lot of files and it would be very convenient to open them directly using python.

EDIT 1: Updated cap file link.

1

There are 1 answers

1
mama On

I can open cap files like this with scapy:

from scapy.all import rdpcap, IP
for p in rdpcap('capfile.cap'):
    print(p[IP].src)