Advertisement
constantin-net

wpa_connect_hidden

Jul 19th, 2021 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.96 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. [ -z "$1" ] && echo "iface" && exit 0
  4.  
  5. iface="$1"
  6.  
  7. dhclient $iface -x
  8. pkill wpa_supplicant
  9. ifconfig $iface down
  10. ifconfig $iface up
  11.  
  12. echo -n "Enter SSID: "
  13. read essid
  14. channel="auto"
  15. mode="managed"
  16. #tests for encryption key
  17. while true; do
  18.     read -r -s -p "$essid: Enter password: " key
  19.     if [ ${#key} -lt 8 ] || [ ${#key} -gt 32 ]; then
  20.         echo "The password must be 8-32 characters"
  21.         :
  22.     else
  23.         break
  24.     fi
  25. done
  26. skey=$(wpa_passphrase "$essid" $key 2>/dev/null | sed -n 's/^[ \t]psk=//gp')
  27. echo "ctrl_interface=/var/run/wpa_supplicant
  28. ap_scan=1
  29. network={
  30. ssid=\"$essid\"
  31. scan_ssid=1
  32. proto=WPA RSN
  33. key_mgmt=WPA-PSK
  34. pairwise=CCMP TKIP
  35. group=CCMP TKIP
  36. psk=$skey
  37. }" > /etc/wpa_supplicant/wpa_supplicant.conf
  38. if [[ -z `cat /etc/network/interfaces | grep $iface` ]]; then
  39.     wpa_supplicant -B -Dwext -i $iface -c /etc/wpa_supplicant/wpa_supplicant.conf
  40.     dhclient $iface
  41. else
  42.     ifup $iface
  43. fi
  44. exit 0
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement