$ cat ~/bin/
check-wifi.sh #!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
log="/tmp/check-wifi.log"
hardwareport="en0"
IP="192.168.0.1"
SSIDs="TP-LINK_EAF8 TP-LINK_5G_EAF8"
SSID=`networksetup -getairportnetwork en0 | awk -F": " '{print $2}'`
test "${SSIDs#*$SSID}" != "${SSIDs}"
if [ "${?}" = "0" ]; then
echo "[`date`] Checking connectivity of ${SSID}" >> "${log}"
ping -c 3 "${IP}" >> "${log}" 2>&1
if [ "${?}" = "2" ]; then
networksetup -setairportpower "${hardwareport}" off; \
networksetup -setairportpower "${hardwareport}" on
echo "[`date`] Turned Wi-Fi (${hardwareport}) Off/On" >> "${log}"
fi
fi