python-Scapy-创建数据包并显示导致> NoneType对象没有属性“ route” <

我刚刚发现了一些奇怪的东西.
进行以下操作

>>> from scapy.layers.inet import Ether,IP,UDP
>>> e=Ether()
>>> i=IP()
>>> u=UDP()
>>> p=e/i/u
>>> p.show()

导致此错误

###[ Ethernet ]###
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lk/virtualenvs/FuzzingEnv/local/lib/python2.7/site-packages/scapy/packet.py", line 838, in show
    reprval = f.i2repr(self,fvalue)
  File "/home/lk/virtualenvs/FuzzingEnv/local/lib/python2.7/site-packages/scapy/fields.py", line 191, in i2repr
    x = self.i2h(pkt, x)
  File "/home/lk/virtualenvs/FuzzingEnv/local/lib/python2.7/site-packages/scapy/layers/l2.py", line 89, in i2h
    x = conf.neighbor.resolve(pkt,pkt.payload)
  File "/home/lk/virtualenvs/FuzzingEnv/local/lib/python2.7/site-packages/scapy/layers/l2.py", line 38, in resolve
    return self.resolvers[k](l2inst,l3inst)
  File "/home/lk/virtualenvs/FuzzingEnv/local/lib/python2.7/site-packages/scapy/layers/inet.py", line 732, in <lambda>
    conf.neighbor.register_l3(Ether, IP, lambda l2,l3: getmacbyip(l3.dst))
  File "/home/lk/virtualenvs/FuzzingEnv/local/lib/python2.7/site-packages/scapy/layers/l2.py", line 57, in getmacbyip
    iff,a,gw = conf.route.route(ip)
AttributeError: 'NoneType' object has no attribute 'route'
>>> ...

但是只是从scapy导入所有内容之后出现这样的错误

>>> ...
>>> from scapy.all import *
WARNING: No route found for IPv6 destination :: (no default route?)
>>> p.show()
###[ Ethernet ]###
  dst       = ff:ff:ff:ff:ff:ff
  src       = 00:00:00:00:00:00
  type      = 0x800
###[ IP ]###
     version   = 4
     ihl       = None
     tos       = 0x0
     len       = None
     id        = 1
     flags     = 
     frag      = 0
     ttl       = 64
     proto     = udp
     chksum    = None
     src       = 127.0.0.1
     dst       = 127.0.0.1
     \options   \
###[ UDP ]###
        sport     = domain
        dport     = domain
        len       = None
        chksum    = None
>>> 

某种程度上似乎可以解决它.怎么会这样?我需要导入一些特殊的模块吗?

解决方法:

您还需要导入Scapy Route模块.

from scapy import route
from scapy.layers.inet import Ether,IP,UDP
e=Ether()
i=IP()
u=UDP()
p=e/i/u
p.show()
上一篇:linux – 如何在scapy中发送多个数据包


下一篇:用scapy在python中编写一个以太网桥