2

I wrote a program (I ran it in the terminal) that goes through a list of terminal commands (Kali Linux).

import subprocess as sub
import time
sub.call(['airmon-ng', 'start', 'wlan0'])
p = sub.call(['airodump-ng','wlan0mon'])
time.sleep(10)
p.kill()

The last commmand is airodump-ng wlan0mon. Everything works fine (everything is displayed in the terminal (beacons, essid, etc.).

After a specified time I wish to kill the process (airodump-ng wlan0mon).

I don't want to press Ctrl + C by hand! p.kill() does not work (maybe improper use).

How can I do this? What command should I send through the subprocess module?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
George Pamfilis
  • 1,397
  • 2
  • 19
  • 37
  • all of this is to automate the task a bit. the program iterates through other commands also. `ifconfig wlan0 down' etc. the code works. i just wish to terminate it. – George Pamfilis Oct 31 '15 at 14:37
  • related: [How to terminate a python subprocess launched with shell=True](http://stackoverflow.com/q/4789837/4279) – jfs Oct 31 '15 at 17:07

1 Answers1

0

The subprocess.call method is a high-level API that waits for the process to terminate before returning its exit code. If you need your main process to continue running while the subprocess runs, you need to use the slightly lower-level API: subprocess.Popen, which starts the process in the background.

Using p = sub.Popen(['airodump-ng','wlan0mon']) instead of p = sub.call(['airodump-ng','wlan0mon']) should work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
pppery
  • 3,731
  • 22
  • 33
  • 46