From 0ac4a00332d8c6fe325e3cbe6aaf82f3bfa1a174 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Mon, 14 Apr 2025 14:59:42 -0500 Subject: [PATCH] Enhance get_aps_on_channel function to include BSSID parameter and improve packet handling --- enrich.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/enrich.py b/enrich.py index 699abc6..0b96394 100755 --- a/enrich.py +++ b/enrich.py @@ -148,7 +148,7 @@ def get_clients_on_channel(capture, ap_channel, ap_bssid): return len(clients) -def get_aps_on_channel(capture, ap_channel): +def get_aps_on_channel(capture, ap_channel, ap_bssid): try: ap_channel = int(ap_channel) except ValueError: @@ -162,33 +162,35 @@ def get_aps_on_channel(capture, ap_channel): if not hasattr(packet, 'radiotap') or not hasattr(packet, 'wlan'): continue - # Check if the packet has frequency info - if not hasattr(packet.radiotap, 'channel') or not hasattr(packet.radiotap.channel, 'freq'): + # Pull the radiotap channel frequency + packet_freq = getattr(packet.radiotap.channel, 'freq', None) + if packet_freq is None: continue - packet_freq = int(packet.radiotap.channel.freq) + packet_freq = int(packet_freq) packet_channel = get_channel_from_freq(packet_freq) - if packet_channel != ap_channel: continue - # Identify AP-advertising frames: Beacon (0x08) or Probe Response (0x05) - subtype_hex = getattr(packet.wlan, 'fc_type_subtype', None) - if subtype_hex is None: + # Manually decode frame control field + fc_raw = getattr(packet.wlan, 'fc', None) + if not fc_raw: continue - subtype = int(subtype_hex, 16) - if subtype not in (0x08, 0x05): + fc_int = int(fc_raw, 16) + frame_type = (fc_int >> 2) & 0b11 + subtype = (fc_int >> 4) & 0b1111 + + # Beacon (8) or Probe Response (5) frames only + if frame_type != 0 or subtype not in (5, 8): continue bssid = getattr(packet.wlan, 'bssid', '').lower() if bssid: aps.add(bssid) - except AttributeError: - continue except Exception as e: - print(f"[!] AP scan error: {e}") + print(f"[DEBUG] Failed packet: {e}") continue return len(aps)