Add channel argument to main function for monitor interface configuration
This commit is contained in:
parent
67213136e1
commit
baa3e864bb
1 changed files with 20 additions and 9 deletions
29
listener.py
29
listener.py
|
@ -23,6 +23,7 @@ ssid_signals = defaultdict(list) # SSID -> list of dBm
|
|||
ap_clients = defaultdict(lambda: defaultdict(int))
|
||||
target_ap_bssid = None
|
||||
beacon_counts = defaultdict(int)
|
||||
current_channel = None
|
||||
|
||||
# === Signal handling ===
|
||||
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("--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("--channel", type=int, help="Channel to lock monitor interface to (overrides main iface)")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
reset_interface(args.monitor_iface)
|
||||
|
@ -182,29 +185,37 @@ def main():
|
|||
print(f" Main interface: {args.main_iface}")
|
||||
print(f" Monitor interface: {args.monitor_iface}")
|
||||
print(f" Output file: {args.outfile}")
|
||||
if args.channel:
|
||||
print(f" Override channel: {args.channel}")
|
||||
|
||||
channel = get_current_channel(args.main_iface)
|
||||
if channel:
|
||||
set_monitor_channel(args.monitor_iface, channel)
|
||||
global target_ap_bssid
|
||||
global current_channel
|
||||
|
||||
current_channel = args.channel or get_current_channel(args.main_iface)
|
||||
if current_channel:
|
||||
set_monitor_channel(args.monitor_iface, current_channel)
|
||||
else:
|
||||
print("[!] Could not determine current channel. Exiting.")
|
||||
sys.exit(1)
|
||||
|
||||
global target_ap_bssid
|
||||
target_ap_bssid = get_connected_bssid(args.main_iface)
|
||||
if not target_ap_bssid:
|
||||
print("[!] Could not determine connected BSSID. ClientsOnAP will be 0.")
|
||||
if not args.channel:
|
||||
target_ap_bssid = get_connected_bssid(args.main_iface)
|
||||
if not target_ap_bssid:
|
||||
print("[!] Could not determine connected BSSID. ClientsOnAP will be 0.")
|
||||
else:
|
||||
print(f"[+] Connected BSSID (target AP): {target_ap_bssid}")
|
||||
else:
|
||||
print(f"[+] Connected BSSID (target AP): {target_ap_bssid}")
|
||||
target_ap_bssid = None # Can't determine AP if we're not associated
|
||||
|
||||
print("[+] Sniffing... (waiting for SIGINT to stop)")
|
||||
|
||||
|
||||
while running:
|
||||
sniff(iface=args.monitor_iface, prn=handle_packet, store=False, timeout=5)
|
||||
|
||||
write_csv(args.outfile)
|
||||
print("\n[+] Final APs counted on this channel:")
|
||||
|
||||
|
||||
for bssid in sorted(aps):
|
||||
ssid = ssid_map.get(bssid, "<unknown>")
|
||||
print(f" - {bssid} (SSID: {ssid})")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue