Python 了解“发送和接收”的标准;回答是;

Python 了解“发送和接收”的标准;回答是;,python,scapy,icmp,Python,Scapy,Icmp,在本例中: >>> 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=0

在本例中:

>>> 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 |>>>
sr1(IP(dst=“192.168.200.254”)/ICMP() 开始排放: ..已完成发送1个数据包。 .* 收到97个数据包,得到1个答案,剩余0个数据包 Scapy使用什么标准将数据包分为这三类? (已收到、已答复、剩余)


还有,有没有办法访问接收到的数据包?此函数似乎只返回应答的数据包。

根据文档说明,函数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
>>> 

显示答案摘要:已发送数据包和已接收数据包。

你完全正确。我想补充一点,您可以直接使用
ans.summary()
来获得与代码相近的内容。