本文介绍了子进程抓取 airodump-ng 的标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用子进程从 airodump-ng 中获取标准输出,但没有运气.我认为我的代码会导致死锁.

I am trying to grab the stdout from airodump-ng using subprocess with no luck.I think my code causes a deadlock.

   airodump = subprocess.Popen(['airodump-ng','mon0'],stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)

    # wait for 15 seconds to find all networks
    time.sleep(15)

    # save the output
    o_airodump = airodump.stdout.read()
    os.kill(airodump.pid, signal.SIGKILL)
    # airodump.terminate
    print(o_airodump)

如何避免这个问题.想不出一个干净的解决方案.

How to avoid this problem. Cant think one clean solution.

推荐答案

不要休眠和等待(这只会导致 airodump 在完整的管道缓冲区上阻塞)并且不要使用无界 read().通信()方法做你需要的:

Don't sleep and wait (that will just cause airodump to block on a full pipe buffer) and don't use an unbounded read(). The communicate() method does what you need:

o_airodump, unused_stderr = airodump.communicate(timeout=15)
airodump.kill()

注意:在 Python 3.3 中引入了关于communication 的超时参数,但尚未完全.;)

Note: The timeout parameter on communicate was introduced in Python 3.3 which isn't quite out yet. ;)

这篇关于子进程抓取 airodump-ng 的标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-18 11:49