无法用python dpkt解析tcpdump捕获的数据。

问题描述 投票:1回答:1

Python dpkt可以解析Wiresharkpcap文件并成功显示数据包数据。

>>> for ts, pkt in pcap:
    eth = dpkt.ethernet.Ethernet(pkt)
    type(eth.data)

<class 'dpkt.ip.IP'>
<class 'dpkt.ip.IP'>

但是当我试图解析tcpdump文件时,得到了以下结果。

>>> for ts, pkt in pcap:
    eth = dpkt.ethernet.Ethernet(pkt)
    type(eth.data)

<type 'str'>
<type 'str'>
<type 'str'>

从Python IDE print中可以看到type(eth.data)是: 'str' 而不是 类'dpkt.ip.IP'。 有谁知道这是根本原因,以及如何使dpkt工作,为 tcpdump 捕获?

python wireshark tcpdump dpkt
1个回答
0
投票

对不起,让你等了这么久。希望你能在不到4年的时间里找到答案。

首先,我应该提到的是,在网络中,有些数据包的以太网层是最后一层。正因为如此,你应该在深入数据包之前检查一下。

对于exampel。

    #Check the if there is an ip layer
    if ether.type == dpkt.ethernet.ETH_TYPE_IP:
        #read the ip layer
        ip = ether.data

我不确定这是否是你的问题. 如果你使用相同的数据包,作为IP层肯定它会是相同的,你以及检查后是。但是,我希望我将帮助一些如何。

有一个伟大的一天!

并祝你好运。

© www.soinside.com 2019 - 2024. All rights reserved.