Skip to content

Instantly share code, notes, and snippets.

@gdevlugt
Created October 20, 2015 11:13
Show Gist options
  • Save gdevlugt/a226d41980c917216d54 to your computer and use it in GitHub Desktop.
Save gdevlugt/a226d41980c917216d54 to your computer and use it in GitHub Desktop.
Simple rudimentary script for Mac OS X which restarts Wifi if the network is unreachable. I need this script because my Mac doesn't work nice with my ISP's cable modem by Ubee.
#!/bin/bash
#
# Restart Wifi if network connection doesn't respond.
# Usage: Open Terminal, and execute this script.
# Optimally you want to use a terminal multiplexer like screen to keep it running
#
while :
do
ping -c 3 google.nl
if [[ $? -ne 0 ]]; then
osascript -e 'display notification "Could not ping google.nl, restarting Wifi connection" with title "Restarting Wifi" sound name "Submarine"'
networksetup -setairportpower en0 off
sleep 5
networksetup -setairportpower en0 on
fi
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment