From 57c9532b88c74844623c7fb5b2313dda51e448d3 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Wed, 16 Apr 2025 10:25:08 -0500 Subject: [PATCH] Refactor analyze_pcap to improve layer checks and SSID extraction handling --- enrich.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/enrich.py b/enrich.py index d0c44a7..ab7512b 100755 --- a/enrich.py +++ b/enrich.py @@ -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