2015-11-29 81 views
1

我想從pcap數據包使用dpkt獲得ipv6擴展頭並將其打印出來。但由於某種原因,它沒有奏效。我嘗試了很多不同的方式。這是導致問題的代碼的一部分。有沒有人有一個想法如何解決這個問題? PS有關於dpkt對IPv6dpkt ipv6擴展頭

# 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 

UPDATE缺乏示例代碼:當我使用dpkt.ip6.IP6FragmentHeader我得到這個錯誤

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

我希望得到這個數據包分片報頭是ICMPv6 wireshark packet

回答

0

我發現問題,它與我使用的版本有關。我已更新版本並解決了問題。

Regards