diff --git a/wifi_deauth.py b/wifi_deauth.py index 76c0ac4..41320de 100644 --- a/wifi_deauth.py +++ b/wifi_deauth.py @@ -1,10 +1,63 @@ #!/usr/bin/env python3 -"""airodump-ng CSV parser for the wifi deauth tool (+ a hardware-free selftest).""" +"""airodump-ng CSV parsing + wireless-interface discovery for the wifi deauth tool.""" import os +import re +import subprocess import sys import tempfile +def run(cmd, timeout=30): + return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout) + + +def list_wifi_interfaces(): + """[{iface, phy, type, addr, monitor_capable}] from `iw dev`.""" + try: + out = run(["iw", "dev"]).stdout + except Exception: + return [] + ifaces, cur_phy, cur = [], None, None + for line in out.splitlines(): + m = re.match(r"phy#(\d+)", line) + if m: + cur_phy = "phy" + m.group(1) + m = re.match(r"\s+Interface (\S+)", line) + if m: + if cur: + ifaces.append(cur) + cur = {"iface": m.group(1), "phy": cur_phy, "type": "?", "addr": "?"} + m = re.match(r"\s+addr (\S+)", line) + if m and cur: + cur["addr"] = m.group(1) + m = re.match(r"\s+type (\S+)", line) + if m and cur: + cur["type"] = m.group(1) + if cur: + ifaces.append(cur) + for it in ifaces: + it["monitor_capable"] = _phy_has_monitor(it["phy"]) + return ifaces + + +def _phy_has_monitor(phy): + if not phy: + return False + out = run(["iw", phy, "info"]).stdout + grab = False + for line in out.splitlines(): + if "Supported interface modes:" in line: + grab = True + continue + if grab: + if re.match(r"\s+\*", line): + if "monitor" in line: + return True + else: + break + return False + + def parse_airodump_csv(path): try: with open(path, encoding="utf-8", errors="replace") as f: