简体   繁体   English

识别icmpv6类型

[英]identifying icmpv6 type

In python-scapy, how can i filter based on icmpv6 type. 在python-scapy中,如何基于icmpv6类型进行过滤。 For example, if icmpv6 type is 135(neighbor solicitation), how can i filter using this type of expression: 例如,如果icmpv6类型为135(邻居请求),我如何使用这种类型的表达式进行过滤:

if(x == 135):  
    do this  

I want to find x in the above expression.There are tags in scapy for TCP, UDP, IPv6 but no tags for ICMPv6. 我想在上面的表达式中找到x.scapy中有用于TCP,UDP,IPv6的标签,但没有用于ICMPv6的标签。 For example, to access a source address parameter in IPv6 header in packet p, i can use p[IPv6].src since the tag IPv6 is there in scapy. 例如,要访问数据包p中IPv6标头中的源地址参数,我可以使用p [IPv6] .src,因为标签IPv6在此处。 But how to access ICMPv6 parameters? 但是如何访问ICMPv6参数?

If it cannot be done using scapy or this method, please suggest alternate approach. 如果无法使用鱼钩或此方法完成操作,请建议使用其他方法。 This problem is bugging me since long time. 长期以来,这个问题困扰着我。 Thanks. 谢谢。

You should use Packet.haslayer('ICMPv6ND_NS') ... 您应该使用Packet.haslayer('ICMPv6ND_NS') ...

>>> from scapy.all import rdpcap
>>> paks = rdpcap('ipv6.pcap')
>>> for idx, pak in enumerate(paks):
...     if pak.haslayer('ICMPv6ND_NS'):
...         print "Index %s: %s" % (idx, repr(pak))
...
Index 3: <Ether  dst=00:21:a0:50:ce:00 src=00:02:55:7b:b2:f6 type=0x86dd |
<IPv6  version=6L tc=0L fl=0L plen=32 nh=ICMPv6 hlim=255 
src=fe80::202:55ff:fe7b:b2f6 dst=fe80::221:a0ff:fe50:ce00 |
<ICMPv6ND_NS  type=Neighbor Solicitation code=0 cksum=0x8b54 R=0L S=0L 
O=0L res=0x0L tgt=fe80::221:a0ff:fe50:ce00 |<ICMPv6NDOptSrcLLAddr  type=1 
len=1 lladdr=00:02:55:7b:b2:f6 |>>>>
>>>

FYI, these are the packets in ipv6.pcap... 仅供参考,这些是ipv6.pcap中的数据包...

[mpenning@Bucksnort ~]$ tshark -r ipv6.pcap
  1   0.000000 2000:fc50:1000:100:202:55ff:fe7b:b2f6 -> 2001:420:1101:1::a ICMPv6 Echo request
  2   1.007475 2000:fc50:1000:100:202:55ff:fe7b:b2f6 -> 2001:420:1101:1::a ICMPv6 Echo request
  3   2.014461 2000:fc50:1000:100:202:55ff:fe7b:b2f6 -> 2001:420:1101:1::a ICMPv6 Echo request
  4   4.997348 fe80::202:55ff:fe7b:b2f6 -> fe80::221:a0ff:fe50:ce00 ICMPv6 Neighbor solicitation
  5   4.998613 fe80::221:a0ff:fe50:ce00 -> fe80::202:55ff:fe7b:b2f6 ICMPv6 Neighbor advertisement
[mpenning@Bucksnort ~]$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM