python构造icmp数据包_python – 在scapy中发送ICMP数据包并选择正确的接口

在使用Scapy库时,作者发现发送ICMP echo-request数据包时,sr()函数未按预期工作,没有显示通过特定接口发送,并且没有接收到响应。然而,使用srp()函数则能成功发送并收到ICMP响应。问题在于何时应该使用sr()和srp(),以及如何指定发送接口。实验表明,不指定接口(iface)可能导致Scapy使用广播地址,而使用srp()则能正确处理ICMP数据包。
摘要由CSDN通过智能技术生成

我们可以将srp()函数用于第3层ICMP数据包吗?我看到当我们制作ICMP echo-r​​equest数据包并使用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

>>>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值