Enhance error handling and debugging in analyze_pcap for SSID and Cisco client count extraction

This commit is contained in:
Yaro Kasear 2025-04-16 11:21:41 -05:00
parent dd82940684
commit 53ec21227c

View file

@ -332,46 +332,55 @@ def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):
if subtype not in (5, 8): # Probe Response or Beacon if subtype not in (5, 8): # Probe Response or Beacon
continue continue
# Grab management layer once
try: try:
mgt = packet.get_multiple_layers('wlan.mgt')[0] mgt = packet.get_multiple_layers('wlan.mgt')[0]
tags = mgt._all_fields.get('wlan.tagged.all', {}).get('wlan.tag', []) tags = mgt._all_fields.get('wlan.tagged.all', {}).get('wlan.tag', [])
ssid = None except Exception as e:
print(f"[DEBUG] Error accessing wlan.mgt tags: {e}")
continue
ssid = None
for tag in tags: for tag in tags:
if tag.get('wlan.tag.number') == '0' and 'wlan.ssid' in tag: tag_number = tag.get('wlan.tag.number')
# SSID
if tag_number == '0' and 'wlan.ssid' in tag:
try:
raw_ssid = tag['wlan.ssid'] raw_ssid = tag['wlan.ssid']
ssid_bytes = bytes.fromhex(raw_ssid.replace(':', '')) ssid_bytes = bytes.fromhex(raw_ssid.replace(':', ''))
ssid = ssid_bytes.decode('utf-8', errors='replace') ssid = ssid_bytes.decode('utf-8', errors='replace')
elif tag.get('wlan.tag.number') == '133': except Exception as e:
print(f"[DEBUG] Error decoding SSID: {e}")
ssid = None
# Cisco Client Count
if tag_number == '133':
try: try:
num_clients = int(tag.get('wlan.cisco.ccx1.clients')) num_clients = int(tag.get('wlan.cisco.ccx1.clients'))
cisco_reported_clients.append(num_clients) cisco_reported_clients.append(num_clients)
except (TypeError, ValueError): except (TypeError, ValueError):
pass # Garbage? We ignore it. pass
if not ssid: if not ssid:
print("[DEBUG] No SSID found in tags.") print("[DEBUG] No SSID found in tags.")
continue continue
except Exception as e:
print(f"[DEBUG] Error parsing SSID or Cisco client count: {e}")
continue
bssid = getattr(wlan, 'bssid', '').lower() bssid = getattr(wlan, 'bssid', '').lower()
if not bssid or bssid == 'ff:ff:ff:ff:ff:ff':
# For debugging purposes, print the SSID and BSSID
print(f"SSID: {ssid}, BSSID: {bssid}")
if not ssid or not bssid or bssid == 'ff:ff:ff:ff:ff:ff':
continue continue
print(f"SSID: {ssid}, BSSID: {bssid}")
bssid_to_ssid[bssid] = ssid bssid_to_ssid[bssid] = ssid
ssid_to_bssids[ssid].add(bssid) ssid_to_bssids[ssid].add(bssid)
signal = getattr(radio, 'dbm_antsignal', None) signal = getattr(radio, 'dbm_antsignal', None)
if signal: if signal:
ssid_signals[ssid].append(int(signal)) ssid_signals[ssid].append(int(signal))
except:
except Exception as e:
print(f"[DEBUG] General packet parse error: {e}")
continue continue
print(f"[DEBUG] SSID to BSSIDs: {ssid_to_bssids}") print(f"[DEBUG] SSID to BSSIDs: {ssid_to_bssids}")