gpt4 book ai didi

python - dpkt ipv6 扩展 header

转载 作者:太空宇宙 更新时间:2023-11-03 17:11:55 45 4
gpt4 key购买 nike

我正在尝试使用 dpkt 从 pcap 数据包中获取 ipv6 扩展 header 并将其打印出来。但由于某种原因它不起作用。我尝试了很多不同的方法。这是导致问题的代码部分。有人知道如何解决这个问题吗?p.s 缺少有关 ipv6 dpkt 的示例代码

    # For each packet in the pcap process the contents
for ts, buf in pcap:

# Unpack the Ethernet frame (mac src/dst, ethertype)
eth = dpkt.ethernet.Ethernet(buf)

# Make sure the Ethernet frame contains an IP packet
# EtherType (IP, ARP, PPPoE, IP6... see http://en.wikipedia.org/wiki/EtherType)
if eth.type != dpkt.ethernet.ETH_TYPE_IP6:
print 'Non IP Packet type not supported %s\n' % eth.data.__class__.__name__
continue

# Now unpack the data within the Ethernet frame (the IP packet)
# Pulling out src, dst, length, fragment info, TTL, and Protocol
ipv6 = eth.data
fh = dpkt.ip.IP_PROTO_FRAGMENT
ic = dpkt.ip.IP_PROTO_ICMP6
icmpv6 = ipv6.data


# get src and dst ip address
src_ip = socket.inet_ntop(AF_INET6, ipv6.src)
dst_ip = socket.inet_ntop(AF_INET6, ipv6.dst)


# Analyzing pcap file offline
#if packet.haslayer(IPv6) and pkt[IPv6].nh == 44 and dpkt.ip6.IP6FragmentHeader.nxt==60 and dpkt.ip6.IP6HopOptsHeader.nxt == 58:
if ipv6.v == 6 and ipv6.nxt==44:

print ipv6.IP6FragmentHeader.nxt

更新:当我使用 dpkt.ip6.IP6FragmentHeader 时出现此错误

AttributeError: 'str' object has no attribute 'IP6FragmentHeader'

我想从这个数据包中获取分段 header ,即 ICMPv6 wireshark packet

最佳答案

我发现了这个问题,它与我使用的版本有关。我已更新版本,问题已解决。

问候

关于python - dpkt ipv6 扩展 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33989586/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com