我们可以使用srp()函数来处理第3层ICMP数据包吗?我看到,当我们制作ICMP回显请求数据包并使用sr()发送/接收时,我们看不到它从接口发出,因此没有来自目的地的响应。但是如果我们使用srp()函数,我们可以看到相同的数据包。什么时候应该使用sr()和何时使用srp()?在文档中,它声明sr()用于L3数据包,srp()用于L2?但在我的情况,我不知道为什么sr()不适用于ICMP数据包?有些专家可以帮我理解吗?发送scapy中的ICMP数据包并选择正确的接口
也有人可以让我知道,如果总是需要“iface”参数。没有了scapy如何知道它应该发送数据包的接口?
案例1:用IFACE SR()函数作为参数:
sr(icmp,iface="eth0")
开始发射:
WARNING: Mac address to reach destination not found. Using broadcast.
Finished to send 1 packets.
^C
Received 0 packets, got 0 answers, remaining 1 packets
(<Results: TCP:0 UDP:0 ICMP:0 Other:0>, <Unanswered: TCP:0 UDP:0 ICMP:1 Other:0>)
在上面,我没有看到的IP任何ICMP应答192.168.25.1
案例2:sr()函数无iface:
sr(icmp)
.Begin emission:
......WARNING: Mac address to reach destination not found. Using broadcast.
.Finished to send 1 packets.
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................^C
Received 887 packets, got 0 answers, remaining 1 packets
(<Results: TCP:0 UDP:0 ICMP:0 Other:0>, <Unanswered: TCP:0 UDP:0 ICMP:1 Other:0>)
如果您看到上面收到的数据包更多,但我没有看到任何ICMP响应。
案例3:发送含有SRP的ICMP数据包()代替SR():
srp(icmp,iface="eth0")
Begin emission:
Finished to send 1 packets.
*
Received 1 packets, got 1 answers, remaining 0 packets
(<Results: TCP:0 UDP:0 ICMP:1 Other:0>, <Unanswered: TCP:0 UDP:0 ICMP:0 Other:0>)
这里我使用了SRP()函数代替SR()函数,现在我看到, ICMP回应请求已正确发送,我也收到了回应。
>>> icmp.show2()
###[ Ethernet ]###
dst: 02:00:00:11:01:03
src: 02:00:20:ee:64:01
type: 0x800
###[ IP ]###
version: 4L
ihl: 5L
tos: 0x0
len: 28
id: 1
flags:
frag: 0L
ttl: 64
proto: icmp
chksum: 0xc78c
src: 192.168.25.2
dst: 192.168.25.1
\options\
###[ ICMP ]###
type: echo-request
code: 0
chksum: 0xf7ff
id: 0x0
seq: 0x0
>>>
很好。我制作了一个ICMP数据包,但没有提供Ether(),我注意到sr()如上所述工作。我还注意到scapy中的路由表不同步。我重新启动了它,现在它正在为sr()正确退出iface。感谢您的及时回应。 – Pradeep 2014-10-09 17:27:47