如何解决以下错误“ AttributeError:'bytes'对象没有属性'sport'“

时间:2019-11-25 14:38:21

标签: python python-3.x wireshark analysis dpkt

我目前正在研究pcap分析仪。我的问题是,DPKT是否仅适用于某些pcap文件?如果是的话,那是什么?

当我尝试分析某个pcap文件时,出现以下错误:

srcport=UDP.sport
AttributeError: 'bytes' object has no attribute 'sport'

代码:

    eth = dpkt.ethernet.Ethernet(buf)
    # Make sure the Ethernet data contains an IP packet
    if not isinstance(eth.data, dpkt.ip.IP):
        print('Non IP Packet type not supported %s\n' % eth.data.__class__.__name__)
        continue

    ip2 = eth.data

    if ip2.p == 17:
        protocol="UDP"
        UDP=ip2.data
        srcport=UDP.sport
        dstport=UDP.dport
        Ulength=UDP.ulen
        check_sum=UDP.sum
        print(*parameters*)

这适用于大多数pcap文件,但有些文件不适用。

0 个答案:

没有答案