了解“已应答”的发送和接收标准

2024-04-26 12:35:56 发布

您现在位置:Python中文网/ 问答频道 /正文

在本例中:

>>> sr1(IP(dst="192.168.200.254")/ICMP())
Begin emission:
..Finished to send 1 packets.
.*
Received 97 packets, got 1 answers, remaining 0 packets
<IP  version=4L ihl=5L tos=0x0 len=28 id=1 flags= frag=0L ttl=255 proto=icmp chksum=0xa7c4 src=4.2.2.1 dst=172.16.20.40 options=[] |<ICMP  type=echo-reply code=0 chksum=0xffff id=0x0 seq=0x0 |<Padding |>>>

Scapy使用什么标准将数据包分为这三类? (已接收、已应答、剩余)

还有,有没有办法访问接收到的数据包?似乎这个函数只返回已应答的数据包。你知道吗


Tags: toipsendid数据包dstpacketsfinished
1条回答
网友
1楼 · 发布于 2024-04-26 12:35:56

根据文档功能,sr1只返回一个应答该数据包的数据包。如果您想收集/操作接收到的和应答的数据包,应该使用函数sr(),它用于发送数据包和接收应答。函数返回几个数据包和答案,以及未应答的数据包。例如:

>>> ans, unans=sr(IP(dst="192.168.0.1") / ICMP())
Begin emission:
.Finished to send 1 packets.
*
Received 2 packets, got 1 answers, remaining 0 packets

返回已应答和未应答的结果列表。和应答结果是成对的(包发送,应答)。所以下面的代码:

>>> for snd, rcv in ans:
...         print("snd={} rcv={}".format(snd.summary(), rcv.summary()))
... 
snd=IP / ICMP 192.168.0.109 > 192.168.0.1 echo-request 0 rcv=IP / ICMP 192.168.0.1 > 192.168.0.109 echo-reply 0
>>> 

显示答案摘要:发送的数据包和接收的数据包。你知道吗

相关问题 更多 >