我们可以将srp()函数用于第3层ICMP数据包吗?我看到当我们制作ICMP echo-request数据包并使用sr()发送/接收时,我们看不到它被发送出接口,因此没有来自目的地的响应.但是如果我们使用srp()函数,我们会看到相同的数据包响应.什么时候应该使用sr()和srp()?在文档中,它声明sr()将用于L3数据包,而srp()将用于L2?但在我的情况下,我不确定为什么sr()不适用于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
(, )
以上我没有看到IP 192.168.25.1的任何ICMP响应
情况2:没有iface的sr()函数:
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
(, )
如果你看到上面收到的数据包更多,但我没有看到任何ICMP响应.
情况3:使用srp()而不是sr()发送ICMP数据包:
srp(icmp,iface="eth0")
Begin emission:
Finished to send 1 packets.
*
Received 1 packets, got 1 answers, remaining 0 packets
(, )
这里我使用srp()函数而不是sr()函数,现在我看到ICMP echo请求已正确发送,我也收到了响应.
>>> 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
>>>