Refactor client counting in get_clients_on_ap to use defaultdict for improved accuracy and stability

This commit is contained in:
Yaro Kasear 2025-04-16 11:54:44 -05:00
parent a951a5eb62
commit 9d446b6353

View file

@ -129,8 +129,8 @@ def convert_timestamp_to_epoch(ts_string):
return None
def get_clients_on_ap(capture, ap_bssid):
clients = set()
ap_bssid = ap_bssid.lower() # Normalize for comparison
clients = defaultdict(int)
ap_bssid = ap_bssid.lower()
for packet in capture:
try:
@ -144,16 +144,17 @@ def get_clients_on_ap(capture, ap_bssid):
# Count any frame *to or from* a client, if AP is involved
if bssid == ap_bssid or sa == ap_bssid or da == ap_bssid:
# If it's the AP sending, add the destination (client)
if sa == ap_bssid and da and da != ap_bssid:
clients.add(da)
if sa == ap_bssid and da and da != ap_bssid and not da.startswith("ff:ff:ff"):
clients[da] += 1
# If it's the client sending, add the source
elif sa and sa != ap_bssid:
clients.add(sa)
elif sa and sa != ap_bssid and not sa.startswith("ff:ff:ff"):
clients[sa] += 1
except AttributeError:
continue
return len(clients)
# Only count clients that show up more than 3 times — tweak as needed
stable_clients = [mac for mac, count in clients.items() if count > 3]
return len(stable_clients)
def get_clients_on_channel(capture, ap_channel, ap_bssid):
try: