New logic and use
This commit is contained in:
parent
6c6930fd5a
commit
97cfd45f5b
74
wpe
74
wpe
@ -1,11 +1,65 @@
|
||||
#!/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., wlan0, eth0). Required.
|
||||
-h, --help Show this help and exit.
|
||||
|
||||
Example:
|
||||
$(basename "$0") -i wlan0
|
||||
EOF
|
||||
}
|
||||
|
||||
iface="wlan0"
|
||||
|
||||
# Check if script is run as root
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "[!] This script must be run as root!" >&2
|
||||
echo "[!] This script requires root permissions." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Translate long options to short for getopts
|
||||
# Keeping the script POSIX-friendly without relying on GNU getopt
|
||||
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
|
||||
|
||||
# Parse short options
|
||||
while getopts ":i:h" opt; do
|
||||
case "$opt" in
|
||||
i) iface="$OPTARG" ;;
|
||||
h) usage; exit 0 ;;
|
||||
\?) echo "Error: Invalid option -$OPTARG" >&2; usage; exit 1 ;;
|
||||
:) echo "Error: Option -$OPTARG requires an argument." >&2; usage; exit 1 ;;
|
||||
end
|
||||
done
|
||||
|
||||
# Require -i/--iface
|
||||
if [[ -z "${iface}" ]]; then
|
||||
echo "Error: A network interface must be pecified with -i/--iface." >&2
|
||||
echo "Example: $(basename "$0") -i wlan0" >&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 hostapd-wpe is installed
|
||||
if ! command -v hostapd-wpe &>/dev/null; then
|
||||
read -r -p "[!] hostapd-wpe is not installed. Install it now? (Y/n): " choice
|
||||
@ -21,24 +75,6 @@ fi
|
||||
fi
|
||||
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}';
|
||||
# echo "[+] Supported modes for each interface:";
|
||||
# iw list | awk '/Wiphy/ {wiphy=$2} /Supported interface modes:/ {getline; while ($1 ~ /^[ ]/) {print " " wiphy " supports: " $1; getline}}';
|
||||
|
||||
# Prompt user for the network card
|
||||
while true; do
|
||||
read -r -p "[?] Enter the interface to use for hostapd-wpe (default: wlan0): " iface
|
||||
iface=${iface:-wlan0}
|
||||
|
||||
if ip link show "$iface" &>/dev/null; then
|
||||
break
|
||||
else
|
||||
echo "[!] Interface $iface does not exist. Please enter a valid interface."
|
||||
fi
|
||||
done
|
||||
|
||||
echo "[+] Preparing $iface for hostapd-wpe..."
|
||||
nmcli device set "$iface" managed no
|
||||
ip link set "$iface" down
|
||||
|
Loading…
x
Reference in New Issue
Block a user