Improve interface availability check in wait_for_interface_up function
This commit is contained in:
parent
9101695db4
commit
c7639d330f
1 changed files with 23 additions and 8 deletions
31
listener.py
31
listener.py
|
@ -258,16 +258,28 @@ def channel_hopper(interface, hop_interval):
|
||||||
def is_deadpoint(ap_bssid):
|
def is_deadpoint(ap_bssid):
|
||||||
return sum(ap_clients[ap_bssid].values()) < 2 # No meaningful client interaction
|
return sum(ap_clients[ap_bssid].values()) < 2 # No meaningful client interaction
|
||||||
|
|
||||||
def wait_for_interface_up(iface, timeout=5):
|
def wait_for_interface_up(interface, timeout=5):
|
||||||
print(f"[~] Waiting for interface {iface} to become available...")
|
import shutil
|
||||||
for _ in range(timeout * 10): # check every 0.1s for `timeout` seconds
|
import time
|
||||||
if iface in psutil.net_if_stats():
|
|
||||||
print(f"[+] Interface {iface} is up!")
|
for _ in range(timeout * 5):
|
||||||
return True
|
result = shutil.which("iw") # Just checking iw exists first
|
||||||
time.sleep(0.1)
|
if not result:
|
||||||
print(f"[!] Interface {iface} did not become available in {timeout} seconds.")
|
print("[!] 'iw' not found.")
|
||||||
return False
|
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 ===
|
# === Main ===
|
||||||
def main():
|
def main():
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
|
@ -284,8 +296,10 @@ def main():
|
||||||
|
|
||||||
reset_interface(args.monitor_iface)
|
reset_interface(args.monitor_iface)
|
||||||
if not wait_for_interface_up(args.monitor_iface):
|
if not wait_for_interface_up(args.monitor_iface):
|
||||||
|
print("[!] Interface failed to become available. Exiting.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
print(f"[+] Starting passive observer.")
|
print(f"[+] Starting passive observer.")
|
||||||
print(f" Main interface: {args.main_iface}")
|
print(f" Main interface: {args.main_iface}")
|
||||||
print(f" Monitor interface: {args.monitor_iface}")
|
print(f" Monitor interface: {args.monitor_iface}")
|
||||||
|
@ -340,6 +354,7 @@ def main():
|
||||||
|
|
||||||
reset_interface(args.monitor_iface)
|
reset_interface(args.monitor_iface)
|
||||||
if not wait_for_interface_up(args.monitor_iface):
|
if not wait_for_interface_up(args.monitor_iface):
|
||||||
|
print("[!] Interface failed to become available. Exiting.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def get_mac_vendor(mac):
|
def get_mac_vendor(mac):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue