2015-08-25 76 views
1

我試圖使用scapy,但我不知道爲什麼有些功能不起作用:的Python 2.7 + Scapy的2.3.1

Traceback (most recent call last): 
    File "/home/user/PycharmProjects/untitled/main.py", line 7, in <module> 
    a.show() 
    File "/usr/lib/python2.7/dist-packages/scapy/packet.py", line 819, in show 
###[ Ethernet ]### 
    reprval = f.i2repr(self,fvalue) 
    File "/usr/lib/python2.7/dist-packages/scapy/fields.py", line 191, in i2repr 
    x = self.i2h(pkt, x) 
    File "/usr/lib/python2.7/dist-packages/scapy/layers/l2.py", line 88, in i2h 
    x = conf.neighbor.resolve(pkt,pkt.payload) 
    File "/usr/lib/python2.7/dist-packages/scapy/layers/l2.py", line 38, in resolve 
    return self.resolvers[k](l2inst,l3inst) 
    File "/usr/lib/python2.7/dist-packages/scapy/layers/inet.py", line 727, in <lambda> 
    conf.neighbor.register_l3(Ether, IP, lambda l2,l3: getmacbyip(l3.dst)) 
    File "/usr/lib/python2.7/dist-packages/scapy/layers/l2.py", line 56, in getmacbyip 
    iff,a,gw = conf.route.route(ip) 
AttributeError: 'NoneType' object has no attribute 'route' 

沒有.show():在

from scapy.layers.inet import * 
a = Ether()/IP(dst='192.168.1.1')/ICMP() 
a.show() 

結果它的作品和:

pck = Ether() 
pck.show() 

也可以。

我嘗試了一些其他功能,如.show,但有時我得到這個錯誤。爲什麼?

回答

0

我認爲你錯過了一個步驟,你的第一行指定了如何構造一些數據包,show試圖解析接收到的數據包。

嘗試類似:

from scapy.layers.inet import * 
a = Ether()/IP(dst='192.168.1.1')/ICMP() # Rule for creating packets 
s,r = sr1(a) # Send & Receive one packet(s) 
r.show() # Show the recieved packet(s) 

這使用您的規則來構建單個數據包,把它和捕捉回覆/答覆,然後顯示實際數據包。

+0

它使回溯(最近通話最後一個): 文件 「/home/inck/PycharmProjects/untitled/main.py」,7號線,在 S,R = SR1(一)#發送&接收一個數據包 文件「/usr/lib/python2.7/dist-packages/scapy/sendrecv.py」,行334,sr1 s = conf.L3socket(filter = filter,nofilter = nofilter,iface = iface) 文件「/usr/lib/python2.7/dist-packages/scapy/arch/linux.py」,行307,在__init__中 self.ins = socket.socket(socket.AF_PACKET,socket.SOCK_RAW, socket.htons(type)) [...] socket.error:[Errno 1]不允許操作 – Chris

+0

您需要超級用戶(root)權限,因爲它會創建套接字。只要sudo,你就要走了。 – Misko

1

您需要導入的一切,那麼請嘗試更改導入語句如下所示:

$ sudo python 
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> from scapy.all import * 
WARNING: No route found for IPv6 destination :: (no default route?) 
>>> a = Ether()/IP(dst='192.168.1.1')/ICMP() 
>>> a.show() 
###[ Ethernet ]### 
    dst  = 74:11:d5:04:1b:82 
    src  = 80:f6:df:59:3d:35 
    type  = 0x800 
###[ IP ]### 
    version = 4 
    ihl  = None 
    tos  = 0x0 
    len  = None 
    id  = 1 
    flags  = 
    frag  = 0 
    ttl  = 64 
    proto  = icmp 
    chksum = None 
    src  = 192.168.0.5 
    dst  = 192.168.1.1 
    \options \ 
###[ ICMP ]### 
     type  = echo-request 
     code  = 0 
     chksum = None 
     id  = 0x0 
     seq  = 0x0 
>>> 
0

據Scapy的努力成爲智能地在鏈路層中有效默認填充。當你不導入整個模塊時,它不能很好地處理事物。

如果您稍微更改一下代碼,以便它不需要執行該檢查,就會生成您的數據包。

from scapy.layers.inet import * 
a = Ether(src='AA:AA:AA:AA:AA:AA', dst='BB:BB:BB:BB:BB:BB')/IP(src='192.168.1.1')/ICMP() 
a.show()