Add interface reset functionality to main loop; ensure proper state before and after sniffing
This commit is contained in:
parent
de6f0b037b
commit
17683f5bd5
1 changed files with 17 additions and 0 deletions
17
listener.py
17
listener.py
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue