Refactor enrichment module by adding utility functions, enhancing CSV handling, and implementing SSID metrics extraction. Update run_test script to improve logging on speed test failures.
This commit is contained in:
parent
4b9ad6f609
commit
55b0835dd7
11 changed files with 541 additions and 406 deletions
43
enrichment/csv_handler.py
Normal file
43
enrichment/csv_handler.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
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 = enriched.with_name(enriched.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', 'CiscoAvgClients', 'CiscoMaxClients', '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}")
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue