问题描述
我想在pyshark的另一个线程中进行捕获。 它在同一线程中运行良好,但是当我在其他线程中运行时,它在pyshark中的第226行[*]处停止,并且无法正常工作。
我当前的代码就是这样描述的。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import datetime
import time
import pyshark
import subprocess
from module.iwlibs import Wireless
import concurrent.futures
def modeMonitor(wlan):
wlanNic = Wireless(wlan)
if wlanNic.getMode() != 'Monitor':
try:
subprocess.check_call(["ip","link","set",wlan,"down"])
subprocess.check_call(["iwconfig","mode","monitor"])
subprocess.check_call(["ip","up"])
except subprocess.CalledProcessError as e:
print(str(e))
sys.exit()
def captest(wlanNic):
cap = pyshark.LiveCapture(interface=wlanNic)
print("start capture...")
for pk in cap.sniff_continuously():
print("Source Address : " + str(pk["WLAN"].get_field("sa")))
print("RSSI : " + str(pk["RAdioTAP"].get_field("dbm_antsignal")))
def Nowtime():
while True:
dt_Now = datetime.datetime.Now()
print(dt_Now.strftime('%Y/%m/%d %H:%M:%s'))
time.sleep(1)
if __name__ == "__main__":
try:
executor = concurrent.futures.ThreadPoolExecutor(max_workers=2)
modeMonitor("wlan1")
executor.submit(Nowtime)
executor.submit(captest,"wlan1") #Doesn't work... Stopping [*] line 226.
#captest("wlan1") #work well But I want to do something else after this.
except Exception as ex:
print(ex)
此外,执行环境如下。
Python 3.7.3 皮沙克0.4.2.11。
* https://github.com/KimiNewt/pyshark/blob/master/src/pyshark/capture/capture.py
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)