Refactor subprocess calls to use safe_call for improved error handling

This commit is contained in:
Yaro Kasear 2025-05-07 08:04:02 -05:00
parent c7639d330f
commit 687d242d89

View file

@ -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: