Skip to content

Instantly share code, notes, and snippets.

@jgamblin
Created September 3, 2016 15:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jgamblin/dd322ba194301608fc0ad3a2bdd4215e to your computer and use it in GitHub Desktop.
Save jgamblin/dd322ba194301608fc0ad3a2bdd4215e to your computer and use it in GitHub Desktop.
OSX Script To Check Wifi
#!/bin/bash
function pause(){
read -p "$*"
}
RED='\033[0;31m'
NC='\033[0m' # NOCOLOR
YELLOW='\033[0;33m'
function HexToDotted (){
echo $1 | sed 's/0x// ; s/../& /g' | tr [:lower:] [:upper:] | while read B1 B2 B3 B4 ; do
echo "ibase=16;$B1;$B2;$B3;$B4" | bc | tr '\n' . | sed 's/\.$//'
done
}
ipaddress=$(ifconfig en0 | grep "inet " 2>&1)
arr=($(ifconfig en0 | grep "inet " 2>&1))
ipaddress=${arr[1]}
netmask=${arr[3]}
netmask=$(HexToDotted $netmask)
broadcast=${arr[5]}
ns=$(scutil --dns | grep -m 1 'nameserver\[[0-9]*\]' | sed 's/^.*: //')
dgw=$(route -n get default | sed -n -e 's/^.*gateway: //p')
publicIP=$(dig +short myip.opendns.com @resolver1.opendns.com)
echo "***********************************************************"
echo " "
echo "You need 6 things for wireless to work on your Mac:"
echo -e "You need a public ${RED}ip address.${NC}"
#if Ip address starts with 169.254, it's probably a self configured address and it suggests a problem.
if [[ $ipaddress == 169.254.* ]]; then
echo $ipaddress " is a self-assigned address and suggests something isn't working with DHCP."
echo "Go read https://technet.microsoft.com/en-us/library/cc958902.aspx on windows"
echo "Go read http://osxdaily.com/2013/02/11/renew-dhcp-lease-mac-os-x/ on a mac"
else
echo "Your local IP address is:" $ipaddress
fi
echo "Your public IP address is:" $publicIP
echo -e "You need to be able to reach your ${RED}default gateway.${NC}"
echo "Your default gateway is:" $dgw
echo -e "You need to have a ${RED}DNS server${NC} configured."
echo -e "You need to be able ${RED}to communicate to the DNS server.${NC}"
echo -e "You need ${RED}DNS lookups to complete.${NC}"
echo "Your DNS server is:" $ns
echo ""
echo "***********************************************************"
echo " "
echo ""
echo "***********************************************************"
echo "Lets Run Some Quick Tests... "
echo "***********************************************************"
echo ""
echo "***********************************************************"
echo "Ping"
echo "***********************************************************"
echo "Running Ping Tests..."
DGWresponse=$(ping -c 1 $dgw | grep time=)
NSresponse=$(ping -c 1 $ns | grep time=)
GOOGresponse=$(ping -c 1 8.8.4.4 | grep time=)
echo "Ping Tests complete!"
if [ -z "$DGWresponse" ]; then
echo -e "${RED}ERROR: couldn't ping the default gateway.${NC} This might not be a big deal- firewalls can block ping requests."
#echo "If DNS pings don't work, you need to troubleshoot this first. Do a DHCP renew and try again. If that fails, reboot your router."
else
echo $DGWresponse
fi
if [ -z "$DGWresponse" ] || [ -z "$GOOGresponse" ]; then
echo -e "${RED}ERROR: Couldn't ping the default gateway or google's external DNS server.${NC} Your connectivity looks really broken."
echo "It could be you're on a public wifi with a captive portal. Try logging into a non-private, non-TLS website from your browser (like verizon.com)."
echo "If you are on your home network, try rebooting the router & logging into it and checkign the error log. If there's nothing obvious, you should call your ISP."
fi
echo "ping response from your nameserver($ns)"
if [ -z "$NSresponse" ]; then
echo -e "${RED}ERROR: couldn't ping the nameserver.${NC} If the nameserver is outside your home, you may want to try rebooting your cable/dsl modem."
else
echo $NSresponse
fi
echo "Ping response from google nameserver(8.8.4.4)"
if [ -z "$GOOGresponse" ]; then
echo -e "${RED}ERROR: couldn't ping the google's nameserver.${NC} If your ISP DNS server & this one aren't reachable, the problem may be at your ISP"
else
echo $GOOGresponse
fi
echo ""
echo "***********************************************************"
echo "DNS"
echo "***********************************************************"
localNSQueryTime=$(dig @$ns google.com | grep Query)
googNSQueryTime=$(dig @8.8.4.4 google.com | grep Query)
echo "Your preconfigured DNS ($ns) querytime:" $localNSQueryTime
echo "Compare this to google's DNS (8.8.4.4) time:" $googNSQueryTime
echo ""
echo "***********************************************************"
echo "SPEED TEST"
echo "***********************************************************"
curl -o /dev/null http://speedtest.wdc01.softlayer.com/downloads/test10.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment