Skip to content

Instantly share code, notes, and snippets.

@rahulsom
Created June 25, 2012 02:55
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rahulsom/2986161 to your computer and use it in GitHub Desktop.
MacbookPro5,1 has a serious problem with it's wireless. Apple will not acknowledge it, but here's a fix
#!/bin/sh
#
# Tests network status and resets Airport if required
#
usage() {
cat << EOF
Usage: $0 options
-h HOST host to ping
-s <ON|OFF> say out loud: on or off default: OFF
EOF
}
SAY=OFF
gateway=`netstat -rn | grep default | tr -s " " | cut -d " " -f 2`
while getopts "hH:sS" OPTION
do
case $OPTION in
h)
gateway=$OPTARG
;;
s)
SAY=$OPTARG
;;
?)
usage
exit 1
esac
done
fix=1
if [ `whoami` != root ]; then
echo "You should be root to run this"
exit 1
fi
echo ""
echo "Will ping $gateway"
echo ""
while [ 1 = 1 ]; do
varStatus=`ping -c 1 -t 2 $gateway | grep "loss"| cut -d , -f 3 | tr -s " "`
lastStatus=$failed
failed=`echo $varStatus | grep "100" -c`
printf "."
if [ $failed = 1 ]; then
if [ $fix = 1 ]; then
if [ "$SAY" = "ON" ]; then
say "Lost connection." &
else
afplay /System/Library/Sounds/Submarine.aiff &
fi
/usr/sbin/networksetup -setairportpower en1 off
/usr/sbin/networksetup -setairportpower en1 on
varDate=`date +"%Y-%m-%d %H:%M:%S"`
varIp=`ifconfig en1 inet | grep inet | tr -s " " | cut -d " " -f 2`
echo ""
echo "$varDate | $varIp | Restarted"
sleep 12
echo Channel: $(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep channel | tr -s " " | cut -d " " -f 3)
else
printf "X"
fi
else
if [ "$lastStatus" = "1" ]; then
if [ "$SAY" = "ON" ]; then
say "Restored" &
fi
fi
fi
sleep 3
done
echo ""
echo "---------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment