Scapy - 如何检查嗅探包的数据包类型

时间:2013-11-04 20:46:45

标签: python scapy sniffing

我正在嗅探数据包,需要知道哪些数据包是ICMPv6 Echo Request数据包,哪些数据包是UDP数据包。

我知道我可以做到

P = sniff(filter='ip6 and host fe80::xx:xx:xx:xx',count=0)

IP in P  #will return false (my packets are IPv6)
UDP in P #will return true (when the specific packet is indeed UDP)

但我不知道如何检查ICMPv6数据包,更具体地说是ICMPv6 Echo 请求数据包......看起来我甚至无法检查IP版本6:

IPv6,IP6,ipv6,ip6,icmpv6,ICMPv6,icmp6,ICMP6全部返回

NameError: name 'x' is not defined

有谁知道这样做的方法吗?

1 个答案:

答案 0 :(得分:4)

如果您使用的是Scapy v1.x,则它不会处理IPv6,因为它在文档的各个位置都有说明。例如,在Download and Installation中:

  

Scapy v2.x。当前的开发版本增加了一些功能(例如IPv6)。

如果你使用的是2.x,它应该可以正常使用IPv6。例如,在我的计算机上(Scapy 2.1.0,Apple预安装的Python 2.7.2,OS X 10.8.5):

>>> P = sniff(filter='ip6', count=0)
… make sure to capture an IPv6 UDP packet …
>>> UDP in P
False
>>> IPv6 in P
False
>>> UDP in P[0]
True
>>> IPv6 in P[0]
True
>>> P[0][IPv6]
<IPv6  version=6L tc=0L fl=0L plen=98 nh=UDP …
>>> ICMPv6EchoRequest in P[0]
False
>>> ICMPv6EchoRequest
<class 'scapy.layers.inet6.ICMPv6EchoRequest'>