无线网卡在几秒钟后返回到管理模式| Python

2024-04-24 08:32:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图把我的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")

但一切都没变


Tags: infrompyselfoslibusrline