Discover wireless interfaces and monitor-mode support via iw

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHYXPc5u9FfVNS8auAUgC4
This commit is contained in:
Franck Thiaw 2026-09-03 08:35:19 +04:00
parent 3393a859c9
commit 4fbf14856c

View file

@ -1,10 +1,63 @@
#!/usr/bin/env python3 #!/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 os
import re
import subprocess
import sys import sys
import tempfile 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): def parse_airodump_csv(path):
try: try:
with open(path, encoding="utf-8", errors="replace") as f: with open(path, encoding="utf-8", errors="replace") as f: