From 9d446b635313954174e4d2f02e2a0f820887968b Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Wed, 16 Apr 2025 11:54:44 -0500 Subject: [PATCH] Refactor client counting in get_clients_on_ap to use defaultdict for improved accuracy and stability --- enrich.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/enrich.py b/enrich.py index e13a733..5f2bac0 100755 --- a/enrich.py +++ b/enrich.py @@ -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: