Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python scap仅指定一个数据包时发送多个数据包_Python_Scapy - Fatal编程技术网

Python scap仅指定一个数据包时发送多个数据包

Python scap仅指定一个数据包时发送多个数据包,python,scapy,Python,Scapy,我正在使用Scapy发送一个简单的ARP请求。我注意到它会发送多个数据包,即使我只给它一个数据包: from scapy.sendrecv import sr1 from scapy.layers.l2 import ARP from typing import Optional def request_mac(target_ip: str, **kwargs) -> Optional[str]: req = ARP(pdst=target_ip) reply = sr1

我正在使用Scapy发送一个简单的ARP请求。我注意到它会发送多个数据包,即使我只给它一个数据包:

from scapy.sendrecv import sr1
from scapy.layers.l2 import ARP
from typing import Optional

def request_mac(target_ip: str, **kwargs) -> Optional[str]:
    req = ARP(pdst=target_ip)
    reply = sr1(req, **kwargs)
    return reply and reply[ARP].hwsrc

request_mac("192.168.123.118", timeout=5)
在Wireshark中,我可以看到它发送两个ARP,而不是一个:

即使输出仅显示一个正在发送:

Begin emission:
Finished sending 1 packets.
................................................................................................................
Received 112 packets, got 0 answers, remaining 1 packets
如果我将
retry
参数设置为
sr1
,我会为每一个显式发送的数据包发送两个数据包


这是预期的行为吗?有没有办法让它只发送一个?当我制作一个端口扫描程序时,我没有看到TCP段的重复发送,所以看起来它可能是特定于ARP的?

这显然是无关的ARP流量。因为照片中的
X.X.X.118
<代码>X.X.X.123在您的代码中

例如,当我运行您的代码时,我只收到一个请求,然后在网络上收到各种arp请求


在我的截图中,我看到来自上游防火墙的每秒192.168.128.5的ARP请求。

哎呀,我问题中的
.123
是以前编辑的一部分。在生成输出的代码中,我使用了
.118
。奇怪的是,你不能复制它。我已经能够在Macos/Linux上复制它,只要ARP数据包在你的子网中发送。第二个数据包在第一个数据包发送后2秒发送。这是
sr
sr1
的问题@RossJacobs是的,对我来说,它们之间也有大约两秒的延迟。我在Windows上。我想在github.com/secdev/scapy上添加一个问题。如果你需要一些有用的东西,只需使用
scapy.layers.l2.arping
@RossJacobs哦,谢谢。这并不是什么大问题,只是在某些情况下,我想限制我产生的流量。事实证明,它对ICMP数据包也起到了同样的作用,使用
sr
对数据包集造成了混乱。我收到重复的回复,而不是每个请求的回复。