Last active
August 29, 2015 14:06
-
-
Save 666threesixes666/d873460c3aec1b5ac09c to your computer and use it in GitHub Desktop.
anthony's conn_man script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#conn_man by anthony guevara, forked by 666threesixes666 | |
#set interface, if you need to manually enter the interface because of multiple cards | |
#change to: IFACE=wlan0 or IFACE=wlp2s0 | |
IFACE=$(ifconfig | grep -o 'wl[a-z0-9]*') | |
#Check if iface is up | |
if( ! $IFACE); then | |
ifconfig $IFACE up && | |
echo -e "\n$IFACE is DOWN. Putting it UP now.\n"; | |
fi | |
if [[ ! -d WPA ]]; then | |
mkdir -p WPA; | |
fi | |
if [[ ! -f WPA/wpa_log ]]; then | |
touch wpa_log; | |
fi | |
if [[ ! -f network_ssid ]]; then | |
touch network_ssid; | |
fi | |
# Clear wap_log every passthrough so we do not generate false errors. | |
echo > WPA/wpa_log | |
# Check for root | |
if [[ $EUID -ne 0 ]]; then | |
echo -e "\nYou must be root.\n"; | |
exit; | |
fi | |
if [[ $1 == "--list" ]]; then | |
iw $IFACE scan | awk '/SSID|signal/{print $2}' | sed -e 'N;s/\n/ /;s/\(\-[0-9.]*\)\(.*\)\([a-zA-Z0-9]*\)/\2 \1/'; | |
exit; | |
elif [[ $1 == "--help" ]]; then | |
echo -e "\nUSAGE: $0 SSID\n\nOptions:\n\n --list - List available network SSID's and their respective signals.\n\n --help - Display this dialog.\n"; | |
exit; | |
else | |
# Check for correct amount of arguments | |
if [[ $# -ne 1 ]]; then | |
echo -e "\nPlease provide an SSID or option.\n"; | |
echo -e "\nUSAGE: $0 SSID\n"; | |
echo -e "\nOptions:\n\n --list - List available network SSID's and their respective signals.\n\n --help - Display this dialog.\n"; | |
exit; | |
else | |
iw $IFACE scan | awk '/SSID/{print $2}' > ESSID; | |
# Check if the SSID exists. | |
if cat ESSID | grep -Fx "$1"; then | |
echo $1 > network_ssid; | |
else | |
echo -e "\nThe SSID $1 does not exist.\n"; | |
exit; | |
fi | |
fi | |
fi | |
fi | |
#(cat ESSID | awk '{print $2}') | |
# Fixes network timeouts | |
iw dev $IFACE set power_save off; | |
# Fixes dropped packets issues | |
iwconfig $IFACE rate 5.5M fixed; | |
# Kills these two programs if they are running | |
if( pgrep dhcpcd ); then | |
killall dhcpcd; | |
fi | |
if( pgrep wpa_supplicant ); then | |
killall wpa_supplicant; | |
fi | |
SCAN=$(cat network_ssid); | |
#AnthonyAP is my Nexus 5 running DU with Unlmtd Data used for tethering. | |
if( ! ( iw dev $IFACE scan ssid $SCAN | grep -o "PSK" | sed -n '1p' ) ); then | |
ifconfig $IFACE down && | |
iwconfig $IFACE ESSID $SCAN && | |
ifconfig $IFACE up && | |
dhcpcd $IFACE && | |
ping google.com; | |
else | |
function WPA_CONN { | |
if [[ ! `cat WPA/${SCAN}.conf | wc -w` -eq 0 ]]; then | |
wpa_supplicant -i $IFACE -c /home/anthony/Documents/Bash/WPA/${SCAN}.conf -f WPA/wpa_log -B && | |
dhcpcd $IFACE && | |
ping google.com; | |
else | |
PASS=$(zenity --entry --text=Password); | |
wpa_passphrase "$SCAN" "$PASS" >> /home/anthony/Documents/Bash/WPA/${SCAN}.conf && | |
if( wpa_supplicant -i $IFACE -c /home/anthony/Documents/Bash/WPA/${SCAN}.conf -f wpa_log -B ); then | |
if( cat WPA/wpa_log | grep "WPA: Invalid .*$" ); then | |
echo -e "\nWrong password.\n"; | |
else | |
dhcpcd $IFACE && | |
ping google.com; | |
fi | |
fi | |
fi | |
} | |
if( ! WPA_CONN ); then | |
echo -e "\nError.\n"; | |
WPA_CONN; | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment