-1

我有一个想使用 python 读取和处理的 cap 文件,我使用了 Scapy 库,但是当尝试使用 rdpcap 函数读取它时,它会引发异常。
CAP 文件
完整的堆栈跟踪:

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

注意:我已经设法在Wireshark中打开cap文件并将其导出为CSV,但我想知道是否有办法解决这个问题,因为我有很多文件,直接使用python打开它们会很方便.

编辑 1:更新了 cap 文件链接。

4

1 回答 1

0

我可以用 scapy 打开这样的 cap 文件:

from scapy.all import rdpcap, IP
for p in rdpcap('capfile.cap'):
    print(p[IP].src)
于 2021-12-21T21:39:25.317 回答