2

What I am trying to do is record the output of airodump-ng every 10 seconds.

First attempt: Going through the airodump-ng documentation they mention such a command --write-interval When I tried using it:sudo airodump-ng mon0 -w testOutput --write-interval 10 -o csv, I got the error that --write-interval is an unrecognized option.

Second attempt: I tried doing this myself in Python. I then came accross the issue of trying to stop the process. The closest I got was this solution.

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

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

This does stop the process, and I do have the relevant output files, BUT what happens is that all my running programs close and I get logged out of Ubuntu.

Additional Info:

Just before everything closes and I got logged out, I saw an error message on the terminal. I quickly screenshot it to see what it said:

Traceback (most recent call last):
  File "airodump-call.py", line 3, in <module> o_airodump, unused_stderr = airodump.communicate(timeout=15)
  File "/usr/lib/python3.5/subprocess.py", line 1072, in communicate stdout, stderr = self.communicate(input, endtime, timeout)
  File "usr/lib/python3.5/subprocess.py", line 1713, in _communicate raise TimeoutExpired(self.args, orig_timeout)
subprocess.TimeoutExpired: Command '['airodump-ng', 'mon0', '-w', 'pythonTest']' timed out after 15 seconds
Community
  • 1
  • 1
Alon
  • 883
  • 1
  • 6
  • 18
  • Does this also happen if you're not using `sudo` (maybe instead run python with sudo)? – handle Aug 13 '16 at 12:52
  • Same thing happens - all programs close and I get logged out of Ubuntu. – Alon Aug 13 '16 at 14:14
  • This is probably some driver problem or something. You might want to check your system's logs. Alternatively, search for similar issues with `airodump-ng`, like http://askubuntu.com/questions/786223/disabling-wifi-while-airodump-ng-is-running-crashes-the-session Do you only have this problem when using python? Try running `sudo airodump-ng mon0 -w testOutput | echo` to see if you get the same; airodump-ng might be doing something odd when it cannot write output anymore. – mweerden Aug 13 '16 at 15:57
  • @mweerden The writing works for a single run in terminal. The problem is that I cannot stop the process in Python (without closing everything and logging me out), and restart it again to take another 10 second interval recording. – Alon Aug 15 '16 at 07:16
  • @AlonBresler Also with the `| echo`? In any case, instead of having the `TimeoutExpired` terminate your script, you can catch it and use `kill()` then. Another option is to use `terminate()` or `send_signal(signal.SIGINT)`. The latter might be most similar to how you terminate `airodump-ng` in your terminal. – mweerden Aug 15 '16 at 08:26
  • @mweerden I tried both catching the TimeoutExpired, and tried using send_signal(signal.SIGINT). But as soon as the timeout expires everything closes and logs out after that line of code is run. – Alon Aug 15 '16 at 10:31
  • The timeout itself should have no effect on the subproces, I believe. Perhaps add an `airodump.wait()` or something to give it some time to deal with the signal. – mweerden Aug 15 '16 at 12:08
  • @mweerden airodump continuously listens to the wifi signal, and doesn't end automatically it has to be killed by the user. So waiting for it to end, the program will wait indefinitely. I really appreciate the help! – Alon Aug 16 '16 at 09:53
  • @AlonBresler I meant adding `wait()` after doing `send_signal()`. – mweerden Aug 16 '16 at 10:46

1 Answers1

1

I've run into the same problem. Despite this being an old post, I post my solution since it could help someone searching for this.

Let's say I run airodump-ng like the OP:

proc = subprocess.Popen(['airodump-ng', 'wlan0mon'])

This can be terminated by sending a SIGINT signal for the pid of the process:

os.kill(proc.pid, signal.SIGINT)

Note: you need import os and import signal