最新的Scapy版本是否支持Python 2.7和Python 3?

时间:2019-10-23 04:07:15

标签: python-3.x linux python-2.7 scapy openwrt

使用GL-inet GL-ar300m-Ext系列并运行Scapy的最新版本2.4.3。使用Python3时,使用setSocket()函数在/usr/lib/python3.6/site-packages/scapy/arch/linux.py中遇到了问题。我确认该文件是相同的。我已经能够在python shell中运行相同的程序,但是作为一个整体程序,当前的scapy版本会失败。

以下是一个简单的程序,旨在检查路由器的连接并检查我们是否可以嗅探发送的数据包。

from scapy.all import *
packets=sniff(filter="host 192.168.8.183 and tcp port 23", count=1)
ans = sr1(packets) #send packet to dst
packets.show()
print(packets)

发现的错误如下:

Traceback (most recent call last):
  File "sniffer.py", line 3, in <module>
    packets=sniff(filter="host 192.168.8.183 and tcp port 23", count=1)
  File "/usr/lib/python3.6/site-packages/scapy/sendrecv.py", line 972, in sniff
    sniffer._run(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/scapy/sendrecv.py", line 842, in _run
    *arg, **karg)] = iface
  File "/usr/lib/python3.6/site-packages/scapy/arch/linux.py", line 475, in __init__
    attach_filter(self.ins, filter, iface)
  File "/usr/lib/python3.6/site-packages/scapy/arch/linux.py", line 161, in attach_filter
    sock.setsockopt(socket.SOL_SOCKET, SO_ATTACH_FILTER, bp)
OSError: [Errno 22] Invalid argument

使用python2运行同一程序时,会发生此错误:

Traceback (most recent call last):
  File "sniffer.py", line 2, in <module>
    from scapy.all import *
  File "/usr/lib/python2.7/site-packages/scapy/all.py", line 16, in <module>
    from arch import *
  File "/usr/lib/python2.7/site-packages/scapy/arch/__init__.py", line 71, in <module>
    from linux import *
  File "/usr/lib/python2.7/site-packages/scapy/arch/linux.py", line 159
    WARNING: No route found for IPv6 destination :: (no default route?)
           ^
SyntaxError: invalid syntax

请提供有关该库所需的任何解决方法或修复方法,或者提出解决此类问题的更好方法。谢谢!

0 个答案:

没有答案