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)
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue