Refactor client counting in get_clients_on_ap to use defaultdict for improved accuracy and stability
This commit is contained in:
parent
a951a5eb62
commit
9d446b6353
1 changed files with 9 additions and 8 deletions
17
enrich.py
17
enrich.py
|
@ -129,8 +129,8 @@ def convert_timestamp_to_epoch(ts_string):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_clients_on_ap(capture, ap_bssid):
|
def get_clients_on_ap(capture, ap_bssid):
|
||||||
clients = set()
|
clients = defaultdict(int)
|
||||||
ap_bssid = ap_bssid.lower() # Normalize for comparison
|
ap_bssid = ap_bssid.lower()
|
||||||
|
|
||||||
for packet in capture:
|
for packet in capture:
|
||||||
try:
|
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
|
# 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 bssid == ap_bssid or sa == ap_bssid or da == ap_bssid:
|
||||||
# If it's the AP sending, add the destination (client)
|
# If it's the AP sending, add the destination (client)
|
||||||
if sa == ap_bssid and da and da != ap_bssid:
|
if sa == ap_bssid and da and da != ap_bssid and not da.startswith("ff:ff:ff"):
|
||||||
clients.add(da)
|
clients[da] += 1
|
||||||
# If it's the client sending, add the source
|
# If it's the client sending, add the source
|
||||||
elif sa and sa != ap_bssid:
|
elif sa and sa != ap_bssid and not sa.startswith("ff:ff:ff"):
|
||||||
clients.add(sa)
|
clients[sa] += 1
|
||||||
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
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):
|
def get_clients_on_channel(capture, ap_channel, ap_bssid):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue