Python可以解析Wireshark/pcap文件并成功地显示数据包数据:
>>> 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打印中可以看到,类型(eth.data)是'str',而不是类'dpkt.ip.IP'.。
有人知道什么是根本原因,以及如何使tcpdump
捕获的dpkt工作吗?
发布于 2020-05-05 20:02:48
很抱歉你等了这么久。我希望你能在不到4年的时间内找到答案。
首先,我要提到的是,网络中有一些数据包,以太网层是其中的最后一层。正因为如此,在你深入到包里之前,你应该检查一下。
例如:
#Check the if there is an ip layer
if ether.type == dpkt.ethernet.ETH_TYPE_IP:
#read the ip layer
ip = ether.data
我不确定这是不是你的问题所在。如果您使用的数据包与ip层相同,请检查是否相同。但是,我希望我能帮上一些忙。
祝你度过美好的一天!
祝你好运。
https://stackoverflow.com/questions/31648931
复制相似问题