Add channel argument to main function for monitor interface configuration

This commit is contained in:
Yaro Kasear 2025-05-01 13:16:29 -05:00
parent 67213136e1
commit baa3e864bb

View file

@ -23,6 +23,7 @@ ssid_signals = defaultdict(list) # SSID -> list of dBm
ap_clients = defaultdict(lambda: defaultdict(int)) ap_clients = defaultdict(lambda: defaultdict(int))
target_ap_bssid = None target_ap_bssid = None
beacon_counts = defaultdict(int) beacon_counts = defaultdict(int)
current_channel = None
# === Signal handling === # === Signal handling ===
def stop_sniff(signum, frame): def stop_sniff(signum, frame):
@ -174,6 +175,8 @@ def main():
parser.add_argument("--main-iface", required=True, help="Active interface (used to determine channel)") parser.add_argument("--main-iface", required=True, help="Active interface (used to determine channel)")
parser.add_argument("--monitor-iface", required=True, help="Monitor interface to sniff on") parser.add_argument("--monitor-iface", required=True, help="Monitor interface to sniff on")
parser.add_argument("--outfile", required=True, help="CSV file to append metrics row") parser.add_argument("--outfile", required=True, help="CSV file to append metrics row")
parser.add_argument("--channel", type=int, help="Channel to lock monitor interface to (overrides main iface)")
args = parser.parse_args() args = parser.parse_args()
reset_interface(args.monitor_iface) reset_interface(args.monitor_iface)
@ -182,23 +185,31 @@ def main():
print(f" Main interface: {args.main_iface}") print(f" Main interface: {args.main_iface}")
print(f" Monitor interface: {args.monitor_iface}") print(f" Monitor interface: {args.monitor_iface}")
print(f" Output file: {args.outfile}") print(f" Output file: {args.outfile}")
if args.channel:
print(f" Override channel: {args.channel}")
channel = get_current_channel(args.main_iface) global target_ap_bssid
if channel: global current_channel
set_monitor_channel(args.monitor_iface, channel)
current_channel = args.channel or get_current_channel(args.main_iface)
if current_channel:
set_monitor_channel(args.monitor_iface, current_channel)
else: else:
print("[!] Could not determine current channel. Exiting.") print("[!] Could not determine current channel. Exiting.")
sys.exit(1) sys.exit(1)
global target_ap_bssid if not args.channel:
target_ap_bssid = get_connected_bssid(args.main_iface) target_ap_bssid = get_connected_bssid(args.main_iface)
if not target_ap_bssid: if not target_ap_bssid:
print("[!] Could not determine connected BSSID. ClientsOnAP will be 0.") print("[!] Could not determine connected BSSID. ClientsOnAP will be 0.")
else: else:
print(f"[+] Connected BSSID (target AP): {target_ap_bssid}") print(f"[+] Connected BSSID (target AP): {target_ap_bssid}")
else:
target_ap_bssid = None # Can't determine AP if we're not associated
print("[+] Sniffing... (waiting for SIGINT to stop)") print("[+] Sniffing... (waiting for SIGINT to stop)")
while running: while running:
sniff(iface=args.monitor_iface, prn=handle_packet, store=False, timeout=5) sniff(iface=args.monitor_iface, prn=handle_packet, store=False, timeout=5)