Python 尝试在 Raspberry Pi 上发送 ARP 请求时引发 AttributeError 3

Python raises AttributeError when attempting to send ARP request on Raspberry Pi 3

我正在开发一个程序,该程序使用 Raspberry Pi 上的 ARP 请求自动扫描本地网络。代码在我的计算机上运行良好,但是当我尝试 运行我的 Raspberry Pi,它失败并出现以下错误:

File "/usr/local/lib/python2.7/dist-packages/scapy/base_classes.py", 
line 241, in __getattr__
    raise AttributeError(attr)
AttributeError: who_has

引发此错误的代码如下:

from scapy import *

result, unanswered = sr(ARP(op=ARP.who_has, psrc="192.168.0.79", pdst="192.168.0.1"), timeout=3)

错误是因为我的树莓派安装了不同版本的scapy,由于某种原因,它不会卸载那个版本。完全重置我的 RPi 并安装正确版本的 scapy (2.3.3) 后,代码现在运行正常。

谢谢 Foon 为我指明了正确的方向。

我也遇到了同样的问题(我用的是scapy 2.4.4), 所以这是另一个可能对你们中的一些人有用的解决方案:

我刚刚通过编码 op="who-has" 而不是 op=ARP.who_has 解决了这个问题。

from scapy import *

result, unanswered = sr(ARP(op="who-has", psrc="192.168.0.79", pdst="192.168.0.1"), timeout=3)