Enhance get_aps_on_channel function to include BSSID parameter and improve packet handling
This commit is contained in:
parent
a1c0c18eb2
commit
0ac4a00332
1 changed files with 15 additions and 13 deletions
28
enrich.py
28
enrich.py
|
@ -148,7 +148,7 @@ def get_clients_on_channel(capture, ap_channel, ap_bssid):
|
||||||
|
|
||||||
return len(clients)
|
return len(clients)
|
||||||
|
|
||||||
def get_aps_on_channel(capture, ap_channel):
|
def get_aps_on_channel(capture, ap_channel, ap_bssid):
|
||||||
try:
|
try:
|
||||||
ap_channel = int(ap_channel)
|
ap_channel = int(ap_channel)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -162,33 +162,35 @@ def get_aps_on_channel(capture, ap_channel):
|
||||||
if not hasattr(packet, 'radiotap') or not hasattr(packet, 'wlan'):
|
if not hasattr(packet, 'radiotap') or not hasattr(packet, 'wlan'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Check if the packet has frequency info
|
# Pull the radiotap channel frequency
|
||||||
if not hasattr(packet.radiotap, 'channel') or not hasattr(packet.radiotap.channel, 'freq'):
|
packet_freq = getattr(packet.radiotap.channel, 'freq', None)
|
||||||
|
if packet_freq is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
packet_freq = int(packet.radiotap.channel.freq)
|
packet_freq = int(packet_freq)
|
||||||
packet_channel = get_channel_from_freq(packet_freq)
|
packet_channel = get_channel_from_freq(packet_freq)
|
||||||
|
|
||||||
if packet_channel != ap_channel:
|
if packet_channel != ap_channel:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Identify AP-advertising frames: Beacon (0x08) or Probe Response (0x05)
|
# Manually decode frame control field
|
||||||
subtype_hex = getattr(packet.wlan, 'fc_type_subtype', None)
|
fc_raw = getattr(packet.wlan, 'fc', None)
|
||||||
if subtype_hex is None:
|
if not fc_raw:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
subtype = int(subtype_hex, 16)
|
fc_int = int(fc_raw, 16)
|
||||||
if subtype not in (0x08, 0x05):
|
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
|
continue
|
||||||
|
|
||||||
bssid = getattr(packet.wlan, 'bssid', '').lower()
|
bssid = getattr(packet.wlan, 'bssid', '').lower()
|
||||||
if bssid:
|
if bssid:
|
||||||
aps.add(bssid)
|
aps.add(bssid)
|
||||||
|
|
||||||
except AttributeError:
|
|
||||||
continue
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[!] AP scan error: {e}")
|
print(f"[DEBUG] Failed packet: {e}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return len(aps)
|
return len(aps)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue