rewrote run_cmd to have a timeout and handle errors a bit differently
This commit is contained in:
parent
851c4c47e4
commit
3314c98fb3
@ -1,16 +1,14 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import string, random, csv, time
|
import string, random, csv, time
|
||||||
|
|
||||||
def run_cmd(cmd, out=subprocess.PIPE):
|
def run_cmd(cmd, out=subprocess.PIPE, timeout=None):
|
||||||
# Just runs a command, supports changing the pipe n stuff
|
# Just runs a command, supports changing the pipe n stuff
|
||||||
|
|
||||||
proc = subprocess.Popen(cmd, stdout = out, stderr = subprocess.PIPE, shell=True)
|
proc = subprocess.Popen(cmd, stdout = out, stderr = subprocess.PIPE, shell=True)
|
||||||
proc.wait()
|
proc.wait(timeout=timeout)
|
||||||
|
|
||||||
|
return (proc.stdout.read().decode(), proc.stderr.read().decode(), proc.returncode)
|
||||||
|
|
||||||
if proc.stdout:
|
|
||||||
return (proc.stdout.read().decode(), proc.returncode)
|
|
||||||
else:
|
|
||||||
return (None, proc.returncode)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -26,15 +24,15 @@ class Sniffer:
|
|||||||
self.create_dir( self.base_dir )
|
self.create_dir( self.base_dir )
|
||||||
|
|
||||||
def enable_monitor_mode(self):
|
def enable_monitor_mode(self):
|
||||||
stdout, code = run_cmd( f"airmon-ng start {self.ifname}" )
|
stdout, stderr, code = run_cmd( f"airmon-ng start {self.ifname}" )
|
||||||
return code == 0
|
return code == 0
|
||||||
|
|
||||||
def disable_monitor_mode(self):
|
def disable_monitor_mode(self):
|
||||||
stdout, code = run_cmd( f"airmon-ng stop {self.ifname}" )
|
stdout, stderr, code = run_cmd( f"airmon-ng stop {self.ifname}" )
|
||||||
return code == 0
|
return code == 0
|
||||||
|
|
||||||
def create_dir(self, base_dir):
|
def create_dir(self, base_dir):
|
||||||
stdout, code = run_cmd( f"mkdir -p {base_dir}" )
|
stdout, stderr, code = run_cmd( f"mkdir -p {base_dir}" )
|
||||||
return code == 0
|
return code == 0
|
||||||
|
|
||||||
|
|
||||||
@ -42,13 +40,13 @@ class Sniffer:
|
|||||||
timeout = int(timeout+0.5)
|
timeout = int(timeout+0.5)
|
||||||
dump_file = f"{self.base_dir}/cap-{ int(time.time()) }"
|
dump_file = f"{self.base_dir}/cap-{ int(time.time()) }"
|
||||||
|
|
||||||
stdout, code = run_cmd(f"airodump-ng --write {dump_file} --write-interval 1 --output-format csv walfa0")
|
stdout, stderr, code = run_cmd(f"airodump-ng --write {dump_file} --write-interval 1 --output-format csv walfa0", timeout=timeout)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
return code
|
return code
|
||||||
|
|
||||||
time.sleep(timeout+.1) # Give a bit of time for airodump to write
|
#time.sleep(timeout+.1) # Give a bit of time for airodump to write
|
||||||
|
|
||||||
stdout, code = run_cmd(f"killall -i airodump-ng")
|
#stdout, code = run_cmd(f"killall -i airodump-ng")
|
||||||
|
|
||||||
full_filepath = f"{dump_file}-01.csv"
|
full_filepath = f"{dump_file}-01.csv"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user