Refactor get_clients_on_channel to improve error handling and remove redundant debug prints

This commit is contained in:
Yaro Kasear 2025-04-11 14:41:40 -05:00
parent ac94b59649
commit 4e530b0a8f

View file

@ -108,15 +108,8 @@ def get_clients_on_channel(capture, ap_channel, ap_bssid):
ap_channel = int(ap_channel)
except ValueError:
print(f"[!] Could not parse channel number: {ap_channel}")
# Print the channel frequency for debugging
print(f"Channel: {ap_channel}")
from_channel_freq = get_channel_from_freq(ap_channel)
if not from_channel_freq:
print(f"[!] Invalid channel: {ap_channel}")
return 0
clients = set()
for packet in capture:
@ -127,11 +120,10 @@ def get_clients_on_channel(capture, ap_channel, ap_bssid):
radio = packet.radiotap
wlan = packet.wlan
# Printing the channel frequency for debugging
print(f"Channel Frequency: {getattr(radio, 'channel_freq', None)}")
packet_freq = int(getattr(radio, 'channel_freq', -1))
if packet_freq != from_channel_freq:
packet_channel = get_channel_from_freq(packet_freq)
if packet_channel != ap_channel:
continue
sa = getattr(wlan, 'sa', '').lower()
@ -139,11 +131,14 @@ def get_clients_on_channel(capture, ap_channel, ap_bssid):
for mac in (sa, da):
if mac and mac != 'ff:ff:ff:ff:ff:ff' and mac != ap_bssid:
clients.add(mac.lower())
clients.add(mac)
except AttributeError:
continue
except Exception as e:
print(f"[!] Error parsing packet: {e}")
continue
return len(clients)
def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):