Add interface reset functionality to main loop; ensure proper state before and after sniffing

This commit is contained in:
Yaro Kasear 2025-05-01 09:16:02 -05:00
parent de6f0b037b
commit 17683f5bd5

View file

@ -4,6 +4,7 @@ import signal
import csv
import sys
import subprocess
import time
from scapy.all import sniff, Dot11, RadioTap
from collections import defaultdict
from datetime import datetime
@ -124,6 +125,19 @@ def write_csv(outfile):
writer.writerow(row)
print(f"[+] Metrics written to {outfile}")
def reset_interface(interface):
print(f"[~] Resetting interface {interface} to default state...")
try:
subprocess.call(["ip", "link", "set", interface, "down"])
time.sleep(1)
subprocess.call(["iw", interface, "set", "type", "managed"])
time.sleep(1)
subprocess.call(["ip", "link", "set", interface, "up"])
time.sleep(1)
print(f"[+] Interface {interface} reset complete.")
except Exception as e:
print(f"[!] Failed to reset interface {interface}: {e}")
# === Main ===
def main():
parser = ArgumentParser()
@ -132,6 +146,8 @@ def main():
parser.add_argument("--outfile", required=True, help="CSV file to append metrics row")
args = parser.parse_args()
reset_interface(args.monitor_iface)
print(f"[+] Starting passive observer.")
print(f" Main interface: {args.main_iface}")
print(f" Monitor interface: {args.monitor_iface}")
@ -150,6 +166,7 @@ def main():
sniff(iface=args.monitor_iface, prn=handle_packet, store=False, timeout=5)
write_csv(args.outfile)
reset_interface(args.monitor_iface)
if __name__ == "__main__":
main()