From 687d242d89aa7c45b1bf85654bf4cf6cf6b88b5b Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Wed, 7 May 2025 08:04:02 -0500 Subject: [PATCH] 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: