Skip to content

Instantly share code, notes, and snippets.

@BirknerAlex
Last active August 24, 2018 19:11
Show Gist options
  • Save BirknerAlex/95505610826c31be2a361b2c90223072 to your computer and use it in GitHub Desktop.
Save BirknerAlex/95505610826c31be2a361b2c90223072 to your computer and use it in GitHub Desktop.
Checking DB Wifi on ICE connection. If the traffic limit of 200MB has been exceeded, doing some magic stuff.
#!/bin/bash
echo "-------------------------"
echo "DB WiFi Online Checker"
echo "Version 1.0"
echo "-------------------------"
if [[ `whoami` != 'root' ]]
then
echo "`date`: Please run this script as root! Try again with \"sudo bash $0\"."
exit 1
fi
while (true)
do
ping -c 3 8.8.8.8 > /dev/null 2>&1
if [[ "$?" == 0 ]]
then
WIFI_SID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep '\sSSID:' | sed 's/.*: //'`
if [[ $WIFI_SID != 'WIFIonICE' ]]
then
echo "`date`: You are not connected to \"WIFIonICE\", exiting now..."
exit 1
fi
echo "`date`: Still online and working, do nothing yet."
else
echo "`date`: Offline, reconnect now with new MAC Address and Hostname."
networksetup -setairportpower en0 off
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' | xargs ifconfig en0 ether
hostname `openssl rand -base64 6`
networksetup -setairportpower en0 on
echo "`date`: Waiting one Minute for reconnecting with new MAC Address and Hostname."
sleep 55
fi
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment