Advertisement
Guest User

Untitled

a guest
Sep 1st, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.66 KB | None | 0 0
  1. #!/bin/bash
  2. if [[ $EUID -ne 0 ]]; then
  3.     echo "This script must be run as root."
  4.     exit 1
  5. fi
  6. echo "Which wireless interface do you wish to configure?"
  7. interfaces=($(ls /sys/class/net | egrep -v 'lo|eth|enp|veth|ppp|tun'))
  8. for (( i = 0; i < ${iLen=${#interfaces[@]}}; i++ )); do echo "($i) ${interfaces[$i]}"; done
  9. echo -en "\nType number and hit [ENTER]: "
  10. read inChoice
  11. clear
  12. if [[ ! " ${interfaces[$inChoice]} " =~ " ${value} " ]]; then
  13.     pkill wpa_supplicant
  14.     ifconfig "${interfaces[$inChoice]}" down
  15.     sleep 1
  16.     sudo ifconfig "${interfaces[$inChoice]}" up
  17.     clear
  18.     echo -e "\nScanning for nearby networks with ${interfaces[$inChoice]}..."
  19.     networks=($(sudo iw dev "${interfaces[$inChoice]}" scan | grep 'SSID' | awk '{print $2}'))
  20.     for (( i = 0; i < ${nLen=${#networks[@]}}; i++ )); do echo "($i) ${networks[$i]}"; done
  21.     echo -en "\nType number and hit [ENTER]: "
  22.     read netChoice
  23.     clear
  24.     if [[ ! " ${networks[$netChoice]} " =~ " ${value} " ]]; then
  25.         if [ -e "${networks[$netChoice]}.conf" ]; then
  26.             echo "Connecting with previous config..."
  27.             sleep 1
  28.         else
  29.             echo -en "\nType the PSK for ${networks[$netChoice]} and hit [ENTER]: "
  30.             read psk
  31.             echo -e "\n\nGenerating WPA config file (${networks[$netChoice]})..."
  32.             wpa_passphrase "${networks[$netChoice]}" "$psk" > "${networks[$netChoice]}.conf"
  33.         fi
  34.         pkill wpa_supplicant
  35.         wpa_supplicant -B -i "${interfaces[$inChoice]}" -c "${networks[$netChoice]}.conf"
  36.         clear
  37.         echo -e "Getting IP, however you can CTRL+C to cancel and still be connected.\n"
  38.         echo "IP: $(curl -s --retry 999 --retry-max-time 0 ipinfo.io/ip)"
  39.     fi
  40. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement