Refactor debug statements in _count_unlinked_devices and related logic for clarity and efficiency
This commit is contained in:
parent
6958e22088
commit
21fcc807ad
1 changed files with 8 additions and 17 deletions
|
@ -168,23 +168,14 @@ class IndexedCapture:
|
||||||
# Determine subtype
|
# Determine subtype
|
||||||
subtype = int(getattr(wlan, 'type_subtype', '0'), 16)
|
subtype = int(getattr(wlan, 'type_subtype', '0'), 16)
|
||||||
|
|
||||||
# Always debug if resolved channel == AP's channel
|
|
||||||
if channel == ap_channel:
|
|
||||||
print(f"[DEBUG] Packet: subtype={subtype}, bssid={bssid}, sa={sa}, da={da}")
|
|
||||||
|
|
||||||
# Track APs (beacons / probe responses only)
|
# Track APs (beacons / probe responses only)
|
||||||
if subtype in (5, 8) and bssid:
|
if subtype in (5, 8) and bssid:
|
||||||
window_aps[channel].add(bssid)
|
window_aps[channel].add(bssid)
|
||||||
if channel == ap_channel:
|
|
||||||
print(f"[DEBUG] [AP] Adding bssid={bssid} to window_aps[{channel}]")
|
|
||||||
|
|
||||||
# Track clients (always)
|
# Track clients (always)
|
||||||
for mac in (sa, da):
|
for mac in (sa, da):
|
||||||
if mac and mac != 'ff:ff:ff:ff:ff:ff':
|
if mac and mac != 'ff:ff:ff:ff:ff:ff':
|
||||||
window_clients[channel].add(mac)
|
window_clients[channel].add(mac)
|
||||||
if channel == ap_channel:
|
|
||||||
print(f"[DEBUG] [CLIENT] Adding mac={mac} to window_clients[{channel}]")
|
|
||||||
|
|
||||||
|
|
||||||
# Track signals
|
# Track signals
|
||||||
signal = getattr(radio, 'dbm_antsignal', None)
|
signal = getattr(radio, 'dbm_antsignal', None)
|
||||||
|
@ -248,15 +239,15 @@ class IndexedCapture:
|
||||||
def _count_unlinked_devices(self, packets, ap_channel):
|
def _count_unlinked_devices(self, packets, ap_channel):
|
||||||
aps = self.channel_to_aps.get(ap_channel, set())
|
aps = self.channel_to_aps.get(ap_channel, set())
|
||||||
ghost_candidates = set()
|
ghost_candidates = set()
|
||||||
|
|
||||||
for packet in packets:
|
for packet in packets:
|
||||||
try:
|
try:
|
||||||
if 'radiotap' not in packet or 'wlan' not in packet:
|
if 'radiotap' not in packet or 'wlan' not in packet:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
radio = packet.radiotap
|
radio = packet.radiotap
|
||||||
wlan = packet.wlan
|
wlan = packet.wlan
|
||||||
|
|
||||||
# Must be on our AP's channel
|
# Must be on our AP's channel
|
||||||
if hasattr(radio, 'channel') and hasattr(radio.channel, 'freq'):
|
if hasattr(radio, 'channel') and hasattr(radio.channel, 'freq'):
|
||||||
freq = int(radio.channel.freq)
|
freq = int(radio.channel.freq)
|
||||||
|
@ -265,23 +256,23 @@ class IndexedCapture:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
sa = getattr(wlan, 'sa', '').lower()
|
sa = getattr(wlan, 'sa', '').lower()
|
||||||
da = getattr(wlan, 'da', '').lower()
|
da = getattr(wlan, 'da', '').lower()
|
||||||
bssid = getattr(wlan, 'bssid', '').lower()
|
bssid = getattr(wlan, 'bssid', '').lower()
|
||||||
|
|
||||||
# If the packet is *talking to* any known AP, it's **linked**, not ghost
|
# If the packet is *talking to* any known AP, it's **linked**, not ghost
|
||||||
if sa in aps or da in aps or bssid in aps:
|
if sa in aps or da in aps or bssid in aps:
|
||||||
continue # Legit traffic, skip
|
continue # Legit traffic, skip
|
||||||
|
|
||||||
# Otherwise, these are "ghost candidates"
|
# Otherwise, these are "ghost candidates"
|
||||||
for mac in (sa, da):
|
for mac in (sa, da):
|
||||||
if mac and mac != 'ff:ff:ff:ff:ff:ff':
|
if mac and mac != 'ff:ff:ff:ff:ff:ff':
|
||||||
ghost_candidates.add(mac)
|
ghost_candidates.add(mac)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return len(ghost_candidates)
|
return len(ghost_candidates)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue