When to use subprocess.call () or subprocess.Popen (), starts airodump

I have this little script that puts your wireless device in monitoring mode. It performs an airodump scan, and then after the scan is complete, it outputs the output to a .txt file or variable, so I can clear the BSSID and any other information that I may need.

I feel that I did not understand the concept or the difference between subprocess.call()and subprocess.Popen().

This is what I have:

def setup_device(): 
    try:
        output = open("file.txt", "w")
        put_device_down = subprocess.call(["ifconfig", "wlan0", "down"])
        put_device_mon = subprocess.call(["iwconfig", "wlan0", "mode", "monitor"]) 
        put_device_up = subprocess.call(["iwconfig", "wlano", "up"])
        start_device = subprocess.call(["airmon-ng", "start", "wlan0"])
        scanned_networks = subprocess.Popen(["airodump-ng", "wlan0"], stdout = output)  
        time.sleep(10)  
        scanned_networks.terminate()

    except Exception, e:
         print "Error:", e

I still don’t know where and when and how to use subprocess.call()andsubprocess.Popen()

What, in my opinion, confuses me more is the arguments stdoutand stderr. What is PIPE?

Another thing that I could fix as soon as I get a better understanding:

running subprocess.Popen() airodump , . ?

+3
1

Popen(), . , .call(), Popen(), API , .

3 '': stdin stdout stderr . , ; stderr, - stdout. Python, subprocess.PIPE, "" . .

airodump-ng wlan0, subprocess.check_output(); PIPE :

scanned_networks = subprocess.check_output(["airodump-ng", "wlan0"])

output , airodump-ng stdout.

, Popen():

proc = subprocess.Popen(["airodump-ng", "wlan0"], stdout=subprocess.PIPE)
for line in proc.stdout:
    # do something with line
proc.terminate()
+6

Source: https://habr.com/ru/post/1617484/


All Articles