Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [[ $EUID -ne 0 ]]; then
- echo "This script must be run as root."
- exit 1
- fi
- echo "Which wireless interface do you wish to configure?"
- interfaces=($(ls /sys/class/net | egrep -v 'lo|eth|enp|veth|ppp|tun'))
- for (( i = 0; i < ${iLen=${#interfaces[@]}}; i++ )); do echo "($i) ${interfaces[$i]}"; done
- echo -en "\nType number and hit [ENTER]: "
- read inChoice
- clear
- if [[ ! " ${interfaces[$inChoice]} " =~ " ${value} " ]]; then
- pkill wpa_supplicant
- ifconfig "${interfaces[$inChoice]}" down
- sleep 1
- sudo ifconfig "${interfaces[$inChoice]}" up
- clear
- echo -e "\nScanning for nearby networks with ${interfaces[$inChoice]}..."
- networks=($(sudo iw dev "${interfaces[$inChoice]}" scan | grep 'SSID' | awk '{print $2}'))
- for (( i = 0; i < ${nLen=${#networks[@]}}; i++ )); do echo "($i) ${networks[$i]}"; done
- echo -en "\nType number and hit [ENTER]: "
- read netChoice
- clear
- if [[ ! " ${networks[$netChoice]} " =~ " ${value} " ]]; then
- if [ -e "${networks[$netChoice]}.conf" ]; then
- echo "Connecting with previous config..."
- sleep 1
- else
- echo -en "\nType the PSK for ${networks[$netChoice]} and hit [ENTER]: "
- read psk
- echo -e "\n\nGenerating WPA config file (${networks[$netChoice]})..."
- wpa_passphrase "${networks[$netChoice]}" "$psk" > "${networks[$netChoice]}.conf"
- fi
- pkill wpa_supplicant
- wpa_supplicant -B -i "${interfaces[$inChoice]}" -c "${networks[$netChoice]}.conf"
- clear
- echo -e "Getting IP, however you can CTRL+C to cancel and still be connected.\n"
- echo "IP: $(curl -s --retry 999 --retry-max-time 0 ipinfo.io/ip)"
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement