diff --git a/src/sniffer.py b/src/sniffer.py index 0e54347..b67df16 100644 --- a/src/sniffer.py +++ b/src/sniffer.py @@ -1,16 +1,14 @@ import subprocess 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 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 ) 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 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 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 @@ -42,13 +40,13 @@ class Sniffer: timeout = int(timeout+0.5) 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: 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"