scapy:发送数据包时出错

时间:2015-04-26 14:33:57

标签: python scapy

我是scapy的新手,我正在关注一些在线教程,但我遇到了这个问题。我能够通过有线连接发送数据包,但是当我尝试无线时,我遇到了这个错误。我试着搜索谷歌,但它没有任何帮助。我希望找到一个解决方案。提前谢谢。

我使用的是Windows 8.1,python 2.7

>>> p=IP(dst="192.168.1.1")/ICMP()
>>> sr1(p)
Begin emission:
ERROR: --- Error sending packets
Traceback (most recent call last):
  File "c:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 374,
 in sndrcv
    pks.send(p)
  File "c:\Python27\lib\site-packages\scapy\arch\pcapdnet.py", line 257, in send

    sx = str(cls()/x)
  File "c:\Python27\lib\site-packages\scapy\packet.py", line 268, in __str__
    return self.build()
  File "c:\Python27\lib\site-packages\scapy\packet.py", line 330, in build
    p = self.do_build()
  File "c:\Python27\lib\site-packages\scapy\packet.py", line 319, in do_build
    pkt = self.self_build()
  File "c:\Python27\lib\site-packages\scapy\packet.py", line 310, in self_build
    p = f.addfield(self, p, val)
  File "c:\Python27\lib\site-packages\scapy\fields.py", line 70, in addfield
    return s+struct.pack(self.fmt, self.i2m(pkt,val))
  File "c:\Python27\lib\site-packages\scapy\layers\l2.py", line 95, in i2m
    return MACField.i2m(self, pkt, self.i2h(pkt, x))
  File "c:\Python27\lib\site-packages\scapy\layers\l2.py", line 89, in i2h
    x = conf.neighbor.resolve(pkt,pkt.payload)
  File "c:\Python27\lib\site-packages\scapy\layers\l2.py", line 38, in resolve
    return self.resolvers[k](l2inst,l3inst)
  File "c:\Python27\lib\site-packages\scapy\layers\inet.py", line 732, in <lambd
a>
    conf.neighbor.register_l3(Ether, IP, lambda l2,l3: getmacbyip(l3.dst))
  File "c:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 292,
 in getmacbyip
    ifip = str(pcapdnet.dnet.intf().get(iff)['addr'])
KeyError: 'addr'
INFO: --- Error sending packets
.........................
Received 25 packets, got 0 answers, remaining 1 packets
WARNING: __del__: don't know how to close the file descriptor. Bugs ahead ! Plea
se report this bug.

4 个答案:

答案 0 :(得分:3)

稍晚,但是:

几个月前我遇到了同样的问题,最终对我有用的是通过另一个网络接口隧道WiFi。似乎问题出在知识产权获取过程中;也许您应该尝试以管理员身份运行,并设置Python和Scapy文件的功能,以便他们具有完全控制权(右键单击&gt;属性 - >安全性)。

使用send / sr / srp等其他方法时遇到同样的问题吗?

答案 1 :(得分:2)

我找到解决方案;}

只需编辑c:\ Python27 \ lib \ site-packages \ scapy \ arch \ windows__init __。py 像这样:

  1. 删除c:\ Python27 \ lib \ site-packages \ scapy \ arch \ windows__init __。pyc
  2. 更改行get(iff)[&#39; addr&#39;])以获取(iff)[&#39; link_addr&#39;])

答案 2 :(得分:0)

如果其他任何人在解决MAC问题之前遇到getmacbyip()超时问题,可以采取以下措施:#/ p>

mac = None
while not mac:
    mac = getmacbyip(ipaddr)
如果没有解决,

getmacbyip()将返回None。这有效,但仍需要几秒钟。我希望这不是必要的,以使其发挥作用。

答案 3 :(得分:0)

我已将我的scapy更新为开发版本(https://github.com/secdev/scapy/),然后它正常运行。