New logic and use
This commit is contained in:
parent
97cfd45f5b
commit
4a19397dbf
94
mon
94
mon
@ -1,36 +1,98 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Display information about the required options
|
||||||
|
usage() {
|
||||||
|
cat <<'EOF'
|
||||||
|
Usage: $(basename "$0") -i <interface>
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-i, --iface Network interface name (e.g., wlan1, eth1). Required.
|
||||||
|
-h, --help Show this help and exit.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
$(basename "$0") -i wlan1
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
iface="wlan1"
|
||||||
|
|
||||||
# Check if script is run as root
|
# Check if script is run as root
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
echo "[!] This script must be run as root!" >&2
|
echo "[!] This script requires root permissions." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# List network interfaces and their capabilities
|
# Translate long options to short for getopts
|
||||||
echo "[+] Available network interfaces:"
|
# Keeping the script POSIX-friendly without relying on GNU getopt
|
||||||
iw dev | awk '/Interface/ {iface=$2; print "- Interface: " iface} /type/ {print " Current Mode: "$2}';
|
if [[ $# -gt 0 ]]; then
|
||||||
|
args=()
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--iface) args+=("-i"); shift ;;
|
||||||
|
--help) args+=("-h"); shift ;;
|
||||||
|
*) args+=("$1"); shift ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
set -- "${args[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
# Prompt user for the network card
|
# Parse short options
|
||||||
while true; do
|
while getopts ":i:h" opt; do
|
||||||
read -r -p "[?] Enter the interface to use for monitoring with airodump-ng (default: wlan1): " iface
|
case "$opt" in
|
||||||
iface=${iface:-wlan1}
|
i) iface="$OPTARG" ;;
|
||||||
|
h) usage; exit 0 ;;
|
||||||
if ip link show "$iface" &>/dev/null; then
|
\?) echo "Error: Invalid option -$OPTARG" >&2; usage; exit 1 ;;
|
||||||
break
|
:) echo "Error: Option -$OPTARG requires an argument." >&2; usage; exit 1 ;;
|
||||||
else
|
end
|
||||||
echo "[!] Interface $iface does not exist. Please enter a valid interface."
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Set up the interface
|
# Require -i/--iface
|
||||||
|
if [[ -z "${iface}" ]]; then
|
||||||
|
echo "Error: A network interface must be pecified with -i/--iface." >&2
|
||||||
|
echo "Example: $(basename "$0") -i wlan1" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Validate the interface exists on the system
|
||||||
|
if ! ip link show "$iface" &>/dev/null; then
|
||||||
|
echo "Error: Interface '$iface' does not exist on this system." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if airodump-ng is installed
|
||||||
|
if ! command -v airodump-ng &>/dev/null; then
|
||||||
|
read -r -p "[!] airodump-ng is not installed. Install it now? (Y/n): " choice
|
||||||
|
choice=${choice:-Y}
|
||||||
|
if [[ $choice =~ ^[Yy]$ ]]; then
|
||||||
|
if ! apt update || ! apt install -y aircrack-ng; then
|
||||||
|
echo "[!] Installation failed. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "[!] airodump-ng is required. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
echo "[+] Preparing $iface for monitor mode..."
|
echo "[+] Preparing $iface for monitor mode..."
|
||||||
nmcli device set "$iface" managed no
|
nmcli device set "$iface" managed no
|
||||||
ip link set "$iface" down
|
ip link set "$iface" down
|
||||||
iw dev "$iface" set type monitor
|
iw dev "$iface" set type monitor
|
||||||
ip link set "$iface" up
|
ip link set "$iface" up
|
||||||
|
|
||||||
|
# Check for hostapd-wpe.conf in the current directory
|
||||||
|
# For monitoring only used for using the same channel as the ap
|
||||||
|
if [[ -f "hostapd-wpe.conf" ]]; then
|
||||||
|
echo "[+] Found hostapd-wpe.conf in the current directory. Using it."
|
||||||
|
source hostapd-wpe.conf
|
||||||
|
else
|
||||||
|
echo "[!] hostapd-wpe.conf not found in the current directory. Using the default: /etc/hostapd-wpe/hostapd-wpe.conf"
|
||||||
|
source /etc/hostapd-wpe/hostapd-wpe.conf
|
||||||
|
fi
|
||||||
|
|
||||||
# Start monitoring
|
# Start monitoring
|
||||||
if ! airodump-ng -w wpa "$iface"; then
|
if ! airodump-ng --channel $channel -w wpa "$iface"; then
|
||||||
echo "[!] Failed to start airodump-ng. Exiting."
|
echo "[!] Failed to start airodump-ng. Exiting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user