Created
November 28, 2020 20:09
-
-
Save netman69/4738c2b0c619529156ab02963f07c53e to your computer and use it in GitHub Desktop.
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/sh | |
iface="wlan0" | |
wpacfg="/tmp/wifizwpasup" | |
wpapid="/tmp/wifizwpapid" | |
dhcpid="/tmp/wifizdhcpid" | |
stop() { | |
if [ -e "$wpapid" ]; then | |
kill $(cat "$wpapid") | |
rm -f "$wpapid" | |
fi | |
if [ -e "$dhcpid" ]; then | |
kill $(cat "$dhcpid") | |
rm -f "$dhcpid" # udhcpc deletes this when killed | |
fi | |
} | |
case $1 in | |
scan) | |
echo "Scanning..." | |
iwlist "$iface" scan | grep SSID | sed 's/^[\t ]*ESSID:\"\(.*\)\"/\t"\1"/' | |
;; | |
conn) | |
stop | |
ip link set wlan0 down | |
ip link set wlan0 up | |
wpa_passphrase "$2" "$3" > "$wpacfg" | |
wpa_supplicant -B -i "$iface" -c "$wpacfg" -P "$wpapid" | |
iwconfig "$iface" essid "$2" | |
udhcpc -i "$iface" -p "$dhcpid" | |
;; | |
stop) | |
stop | |
;; | |
*) | |
echo "usage:" | |
echo " $0 scan" | |
echo " scan for networks" | |
echo " $0 conn <ESSID> <PSK>" | |
echo " connect" | |
echo " $0 stop" | |
echo " disconnect" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment