Refactor get_aps_on_channel to improve channel frequency validation and packet handling

This commit is contained in:
Yaro Kasear 2025-04-15 09:13:40 -05:00
parent 9a13209620
commit 5d000b2a10

View file

@ -155,13 +155,6 @@ def get_aps_on_channel(capture, ap_channel):
print(f"[!] Could not parse channel number: {ap_channel}")
return 0
channel_info = get_freq_details(ap_channel)
if not channel_info:
print(f"[!] Invalid channel: {ap_channel}")
return 0
from_channel_freq = channel_info["freq"]
aps = set()
for packet in capture:
@ -170,14 +163,26 @@ def get_aps_on_channel(capture, ap_channel):
print(f"[!] Packet missing radiotap or wlan layer: {packet}")
continue
# Match channel frequency
freq = int(getattr(packet.radiotap, 'channel_freq', -1))
if freq != from_channel_freq:
print(f"[!] Frequency mismatch: {freq} != {from_channel_freq}")
radio = packet.radiotap
wlan = packet.wlan
if not hasattr(radio, 'channel') or not hasattr(radio.channel, 'freq'):
print(f"[!] Packet missing channel frequency: {packet}")
continue
packet_freq = int(radio.channel.freq)
packet_channel = get_channel_from_freq(packet_freq)
# For debugging purposes, print the channel and frequency
# print(f"Packet Channel: {packet_channel}, Frequency: {packet_freq} MHz")
if packet_channel != ap_channel:
print(f"[!] Packet not on specified channel {ap_channel}: {packet_channel}")
continue
# Check for beacon or probe response
ts_hex = getattr(packet.wlan, 'type_subtype', None)
ts_hex = getattr(wlan, 'type_subtype', None)
if ts_hex is None:
print(f"[!] Missing type_subtype in packet: {packet}")
continue
@ -191,7 +196,7 @@ def get_aps_on_channel(capture, ap_channel):
continue
# Grab BSSID
bssid = getattr(packet.wlan, 'bssid', '').lower()
bssid = getattr(wlan, 'bssid', '').lower()
if bssid and bssid != 'ff:ff:ff:ff:ff:ff':
aps.add(bssid)