airodump-ng output with python subprocess.Popen coummunicate method

时光毁灭记忆、已成空白 提交于 2019-12-10 15:22:41

问题


Hi I am trying to get continuous output from airodump-ng mon0

For that reason I was trying to read the output of airodump-ng mon0 after certain time with Popen.communicate but still cannot get anything.

import subprocess

airodump = subprocess.Popen(['airodump-ng', 'mon0'],
                        stdin=subprocess.PIPE,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)
try:
    o_airodump, unused_stderr = airodump.communicate(timeout=15)
except subprocess.TimeoutExpired as e:
    airodump.kill()
    o_airodump, unused_stderr = airodump.communicate()
    print(o_airodump)
    print(unused_stderr)

When I run this it gets stuck at:

o_airodump, unused_stderr = airodump.communicate()

I am totally stuck now. And unable to find any other ways. Please help.


回答1:


I used the following code to retreive the list of avaible wifi networks after 60 seconds:

def find_wifi(interface):
    table = ''
    stdout = []
    timeout = 60
    table_start = re.compile('\sCH')
    start_time = time.time()

    airodump = subprocess.Popen(['airodump-ng', interface], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, bufsize=1)

    while time.time() < start_time + timeout:
        line = airodump.stdout.readline()
        if table_start.match(line):
            table = ''.join(stdout)
            stdout = []
        stdout.append(line)
    airodump.terminate()
    print(table)


来源:https://stackoverflow.com/questions/45074734/airodump-ng-output-with-python-subprocess-popen-coummunicate-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!