#!/usr/bin/env bash

# Check if script is run as root
if [[ $EUID -ne 0 ]]; then
    echo "[!] This script must be run as root!" >&2
    exit 1
fi

# List network interfaces and their capabilities
echo "[+] Available network interfaces:"
iw dev | awk '/Interface/ {iface=$2; print "- Interface: " iface} /type/ {print "  Current Mode: "$2}';

# Prompt user for the network card
while true; do
    read -r -p "[?] Enter the interface to use for monitoring with airodump-ng (default: wlan1): " iface
    iface=${iface:-wlan1}
    
    if ip link show "$iface" &>/dev/null; then
        break
    else
        echo "[!] Interface $iface does not exist. Please enter a valid interface."
    fi
done

# Set up the interface
echo "[+] Preparing $iface for monitor mode..."
nmcli device set "$iface" managed no
ip link set "$iface" down
iw dev "$iface" set type monitor
ip link set "$iface" up

# Start monitoring
if ! airodump-ng -w wpa "$iface"; then
    echo "[!] Failed to start airodump-ng. Exiting."
    exit 1
fi