Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tshirtman/ebe8fdc20ce4dc195fb07c21628ae0da to your computer and use it in GitHub Desktop.
Save tshirtman/ebe8fdc20ce4dc195fb07c21628ae0da to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
netsh="/c/Windows/System32/netsh.exe"
icon_reconnecting="/usr/share/icons/ubuntu-mono-dark/actions/24/system-restart-panel.svg"
message_reconnecting="wifi reconnecting"
icon_connected="/usr/share/icons/Humanity/actions/16/dialog-ok.svg"
message_connected="wifi connected"
test_host="1.1.1.1"
ssid="XXXXXXXX"
check_timeout=2
recheck_timeout=1
notify="notify-send.py -a netwatch.sh -t 2"
do_notify=true
check_connection() {
timeout=$1
ping -c 1 -W $timeout $test_host > /dev/null 2>&1
return $?
}
reset_connection() {
$netsh wlan disconnect > /dev/null >&1
$netsh wlan connect $ssid > /dev/null >&1
check_connection $recheck_timeout
return $?
}
notify() {
$do_notify && $notify $@
}
while true
do
check_connection $check_timeout
if [ $? -gt 0 ]; then
notify -i $icon_reconnecting $message_reconnecting
echo -n "X"
count=0
reset_connection
while [ $? -gt 0 ]; do
count=$((count+1))
echo -n "?"
sleep .1
if [ $((count % 10)) -eq 0 ]; then
reset_connection
else
check_connection $recheck_timeout
fi
done
notify -i $icon_connected $message_connected
else
echo -n "."
sleep 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment