Created
July 16, 2014 13:56
-
-
Save Maffsie/cbc12b5343d0ee21d70c 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
#!/usr/bin/env bash | |
IFUP="/sbin/ifup" | |
IFDN="/sbin/ifdown" | |
PING="/bin/ping" | |
WLAN="wlan0" | |
PNGA="-c 1 -I $WLAN -W 1" | |
PNGT="94.23.194.120" | |
PNGF="8.8.8.8" | |
PNGR="192.168.0.1" | |
ITRA=0 | |
function do_ping () { | |
tgt=$1 | |
$PING $PNGA $tgt >/dev/null 2>&1 | |
if [ $? -eq 0 ]; then return 0; else return 1; fi | |
} | |
function do_chk () { | |
do_ping $PNGT && return 0 | |
do_ping $PNGF && return 0 | |
do_ping $PNGR && echo "No internet connectivity, but local connectivity seems to work." && return 0 | |
return 1 | |
} | |
do_chk && exit | |
for ((;;)); do | |
echo "Cycling $WLAN..." | |
$IFDN $WLAN | |
sleep 5 | |
$IFUP $WLAN | |
sleep 5 | |
do_chk && break | |
ITRA=$(($ITRA+1)) | |
if [ $ITRA -gt 2 ]; then | |
echo "Looped three times, giving up." | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment