import csv import os from pathlib import Path def read_csv_input(path): """Read a CSV file and return a list of row dictionaries.""" with open(path, newline='', encoding='utf-8') as infile: reader = csv.DictReader(infile) rows = list(reader) print(f"[+] Loaded {len(rows)} rows from {path}") return rows, reader.fieldnames def write_enriched_csv(path, fieldnames, rows): """Write enriched rows to the specified output CSV.""" with open(path, 'w', newline='', encoding='utf-8') as outfile: writer = csv.DictWriter(outfile, fieldnames=fieldnames) writer.writeheader() for row in rows: writer.writerow(row) print(f"[+] Wrote {len(rows)} rows to {path}") def write_ssid_sidecar(enriched_path, ssid_summary): """ Given the path to the enriched CSV and the SSID summary, write a sidecar CSV file next to it. """ enriched = Path(enriched_path) ssid_outfile = Path(enriched_path).with_name(Path(enriched_path).stem + '-ssid-metrics.csv') with ssid_outfile.open('w', newline='', encoding='utf-8') as f: fieldnames = [ 'SSID', 'Hidden', 'Open', 'BSSID_Count', 'BSSIDs', 'Avg_Signal', 'Max_Signal', 'Min_Signal', 'Clients_Seen', 'PacketCount' ] writer = csv.DictWriter(f, fieldnames=fieldnames) writer.writeheader() for row in ssid_summary: writer.writerow(row) print(f"[+] Wrote SSID metrics to {ssid_outfile}")