Refactor analyze_pcap to improve layer checks and SSID extraction handling

This commit is contained in:
Yaro Kasear 2025-04-16 10:25:08 -05:00
parent 7fbdcb310a
commit 57c9532b88

View file

@ -317,8 +317,7 @@ def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):
try:
print(f"[DEBUG] Layers: {[layer.layer_name for layer in packet.layers]}")
if 'radiotap' not in packet or 'wlan' not in packet or not 'wlan.mgt' in packet.get_multiple_layers('wlan.mgt'):
print(f"[DEBUG] Skipping packet due to missing layers: {packet}")
if 'radiotap' not in packet or 'wlan' not in packet:
continue
radio = packet.radiotap
@ -334,7 +333,12 @@ def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):
if subtype not in (5, 8): # Probe Response or Beacon
continue
ssid = getattr(packet.wlan.mgt, 'ssid', None)
try:
mgt = packet.get_multiple_layers('wlan.mgt')[0]
ssid = mgt.get_field('ssid')
except (IndexError, AttributeError):
continue
bssid = getattr(wlan, 'bssid', '').lower()
# For debugging purposes, print the SSID and BSSID