From c7639d330f042e0e1b6adde049ee2a15a011dae0 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Wed, 7 May 2025 08:00:43 -0500 Subject: [PATCH 1/3] Improve interface availability check in wait_for_interface_up function --- listener.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/listener.py b/listener.py index 3f431d4..1f2a13a 100755 --- a/listener.py +++ b/listener.py @@ -258,16 +258,28 @@ def channel_hopper(interface, hop_interval): def is_deadpoint(ap_bssid): return sum(ap_clients[ap_bssid].values()) < 2 # No meaningful client interaction -def wait_for_interface_up(iface, timeout=5): - print(f"[~] Waiting for interface {iface} to become available...") - for _ in range(timeout * 10): # check every 0.1s for `timeout` seconds - if iface in psutil.net_if_stats(): - print(f"[+] Interface {iface} is up!") - return True - time.sleep(0.1) - print(f"[!] Interface {iface} did not become available in {timeout} seconds.") +def wait_for_interface_up(interface, timeout=5): + import shutil + import time + + for _ in range(timeout * 5): + result = shutil.which("iw") # Just checking iw exists first + if not result: + print("[!] 'iw' not found.") + return False + + try: + info = subprocess.check_output(["iw", "dev"]).decode() + if f"Interface {interface}" in info: + if "type monitor" in info: + return True + except subprocess.CalledProcessError: + pass + time.sleep(0.2) + print(f"[!] Timeout waiting for interface {interface} to be up and in monitor mode.") return False + # === Main === def main(): parser = ArgumentParser() @@ -284,8 +296,10 @@ def main(): reset_interface(args.monitor_iface) if not wait_for_interface_up(args.monitor_iface): + print("[!] Interface failed to become available. Exiting.") sys.exit(1) + print(f"[+] Starting passive observer.") print(f" Main interface: {args.main_iface}") print(f" Monitor interface: {args.monitor_iface}") @@ -340,6 +354,7 @@ def main(): reset_interface(args.monitor_iface) if not wait_for_interface_up(args.monitor_iface): + print("[!] Interface failed to become available. Exiting.") sys.exit(1) def get_mac_vendor(mac): From 687d242d89aa7c45b1bf85654bf4cf6cf6b88b5b Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Wed, 7 May 2025 08:04:02 -0500 Subject: [PATCH 2/3] Refactor subprocess calls to use safe_call for improved error handling --- listener.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/listener.py b/listener.py index 1f2a13a..77dc4d3 100755 --- a/listener.py +++ b/listener.py @@ -39,6 +39,12 @@ vendor_cache = {} CHANNEL_LIST = [1, 6, 11, 36, 40, 48, 52, 64, 100, 104, 108, 112, 149, 153, 161] # Channels to hop CHANNEL_HOP_INTERVAL = 5 # Seconds per channel +def safe_call(cmd): + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError as e: + print(f"[!] Command failed: {' '.join(cmd)}\n{e}") + def get_channel_from_freq(freq): if 2412 <= freq <= 2472: return (freq - 2407) // 5 @@ -202,11 +208,11 @@ def write_csv(outfile): def reset_interface(interface): print(f"[~] Resetting interface {interface} to default state...") try: - subprocess.call(["ip", "link", "set", interface, "down"]) + safe_call(["ip", "link", "set", interface, "down"]) time.sleep(1) - subprocess.call(["iw", interface, "set", "type", "monitor"]) + safe_call(["iw", interface, "set", "type", "monitor"]) time.sleep(1) - subprocess.call(["ip", "link", "set", interface, "up"]) + safe_call(["ip", "link", "set", interface, "up"]) time.sleep(1) print(f"[+] Interface {interface} reset complete.") except Exception as e: From 4f627a819df6ef5065155a04635e764b3bf0d222 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Wed, 7 May 2025 08:04:36 -0500 Subject: [PATCH 3/3] Remove interface availability check in main function to streamline execution flow --- listener.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/listener.py b/listener.py index 77dc4d3..697e9dc 100755 --- a/listener.py +++ b/listener.py @@ -359,9 +359,6 @@ def main(): print(f" {bssid} → {vendor}") reset_interface(args.monitor_iface) - if not wait_for_interface_up(args.monitor_iface): - print("[!] Interface failed to become available. Exiting.") - sys.exit(1) def get_mac_vendor(mac): prefix = mac.upper()[0:8].replace(":", "-")