【问题标题】:Opening CAP file in Python using Scapy libraries raises and exception使用 Scapy 库在 Python 中打开 CAP 文件引发和异常
【发布时间】:2022-01-23 05:53:25
【问题描述】:

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

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 文件链接。

【问题讨论】:

    标签: python scapy cap


    【解决方案1】:

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

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

    【讨论】:

    • 我不适合我,你可以试试我提供的文件,看看它是否损坏?
    猜你喜欢
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-19
    相关资源
    最近更新 更多