scapy sr函数不返回答案

2024-05-20 19:23:26 发布

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

我想用scapy做一个隐形SYN扫描。我在书里读到关于sr函数的。它会对我发送的数据包做出响应。
例如,我尝试运行以下命令:

>>> ans,unans = sr(IP(dst="192.168.1.1")/TCP(dport=[22,80,443],flags="S"))

也就是说,我想通过TCP/IP发送一个SYN包到192.168.1.1。
我本以为会立刻得到以下答案:

^{pr2}$

但是,我让它运行了2分钟,sr没有完成。此外,在强制它停止(CTRL+C)之后,我得到了以下答案:

Begin emission:
.Finished to send 3 packets.
......................................^C
Received 2040 packets, got 0 answers, remaining 3 packets

我也尝试了更多的例子,结果都是这样。
有人知道为什么会这样吗?我该怎么解决呢?我的网络配置有问题吗?在

另外,我想补充一点,我试过在两台不同的ubuntu虚拟机上,在两台不同的电脑上,但在同一个家庭网络上。在

谢谢。在


Tags: 函数答案命令ip隐形数据包scapytcp
1条回答
网友
1楼 · 发布于 2024-05-20 19:23:26

您需要添加timeout选项,否则sr()将永远运行

ans,unans = sr(IP(dst="192.168.1.1")/TCP(dport=[22,80,443],flags="S", timeout =1))

timeout: how much time to wait after the last packet has been sent. By default, sr will wait forever and the user will have to interrupt (CtrlC) it when he expects no more answers.

相关问题 更多 >