我正在尝试将我的WN722N无线卡置于监控模式,同时处于Python环境中。我使用python-wifi库以及命令行将无线卡放入监视器,但过了一段时间后它返回到之前的状态并返回OSError。
这就是我想要做的事情:
iface = raw_input("Wireless Interface") #wlan1 in my case
os.system('ip link set %s down' % iface)
os.system('iwconfig %s mode monitor' % iface)
os.system('ip link set %s up' % iface)
实际上它确实可以工作并将我的无线卡(wlan1)置于监控模式但不超过5到6秒,并且在后台运行的其中一个线程中出现错误。线程代码是:
from scapy.all import *
from threading import Thread
def function(pkt):
if pkt.haslayer(Dot11Beacon):
<...snipped...>
sniff(iface=<monitor mode interface here>, prn=function)
5到6秒后出现的错误:
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "python.py", line 113, in depDev
p = sendp(pckt, iface=interface)
File "/usr/lib/python2.7/dist-packages/scapy/sendrecv.py", line 278,
in sendp
return __gen_send(conf.L2socket(iface=iface, *args, **kargs), x,
inter=inter, loop=loop, count=count,
File "/usr/lib/python2.7/dist-packages/scapy/arch/linux.py", line 434,
in __init__
_flush_fd(self.ins)
File "/usr/lib/python2.7/dist-packages/scapy/arch/linux.py", line 312,
in _flush_fd
os.read(fd,MTU)
OSError: [Errno 100] Network is down
我也尝试过使用python-wifi
from pythonwifi.iwlibs import Wireless
dev = Wireless(iface)
dev.setMode("Monitor")
但没有改变