Skip to content

Instantly share code, notes, and snippets.

@ericjster
Last active July 16, 2020 22:10
Show Gist options
  • Save ericjster/46636281723eb6ff46d5b7eeb2b8b14d to your computer and use it in GitHub Desktop.
Save ericjster/46636281723eb6ff46d5b7eeb2b8b14d to your computer and use it in GitHub Desktop.
Ping forever
#/bin/bash
# Log wifi and internet connectivity info.
# Note that 'airport' can do logging also.
#
# 8.8.8.8 = Google primary dns server
# 8.8.4.4 = Google secondary dns server
# 4.2.2.2 = Level 3 Communications dns server
# 1.1.1.1 = Cloudflare and APNIC dns server
# 208.67.222.222 = Cisco OpenDNS
#
# http://www.msftncsi.com/ncsi.txt
# Should return the text: "Microsoft NCSI"
# See: https://technet.microsoft.com/en-us/library/cc766017(v=ws.10).aspx
# Microsoft Network Connectivity Status Indicator
# https://kx.cloudingenium.com/microsoft/servers/windows-servers/what-is-www-msftncsi-com/
# They know the static IP address and they do DNS name lookup, then get file time, then get file.
# So they can distinguish between different types of problems.
# http://blog.superuser.com/2011/05/16/windows-7-network-awareness/
#
# See: https://superuser.com/questions/769005/what-is-a-external-reliable-ip-address-to-ping-to-check-if-internet-is-available
#
# http://etherealmind.com/what-is-the-best-ip-address-to-ping-to-test-my-internet-connection/
# OpenDNS 208.67.222.222 and 208.67.220.220
#
# curl --location --silent http://www.isup.me/bogus.godaddy.com | grep "It.*just you"
# It's not just you! <a href="http://bogus.godaddy.com" class="domain">bogus.godaddy.com</a> looks down from here.
# curl --location --silent http://www.isup.me/bing.com | grep "It.*just you"
# It's just you. <a href='http://bing.com' class="domain">bing.com</a></span> is up.
#
# https://discussions.apple.com/thread/7262077?start=0&tstart=0
# Macbook holds on to weak signal.
# https://apple.stackexchange.com/questions/66919/how-to-enable-faster-wifi-roaming-with-mac-os-x-airport-base-stations
# https://apple.stackexchange.com/questions/178985/how-to-get-osx-to-pick-the-strongest-wifi-signal-with-identical-ssids
LOGFILE=ping_log.txt
while [ 1 -eq 1 ]; do
BEGTIME=$SECONDS
DATE=`date +%Y-%m-%d:%H:%M:%S`
TIMESTAMP=`date "+%y%m%d_%H%M%S"` #add %3N to get milliseconds
echo "=================================================="
echo "$DATE"
echo "$TIMESTAMP"
echo
if [ "$(uname)" == "Darwin" ]; then
#/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I
echo
fi
# ping -c 3 192.168.1.1
# echo
#ping -c 3 192.168.1.2
#echo
#ping -c 3 192.168.1.3
#echo
#ping -c 3 192.168.1.4
#echo
# ping -c 3 192.168.3.1
# echo
ping -c 3 8.8.8.8
echo
ping -c 3 4.2.2.2
echo
ping -c 3 1.1.1.1
echo
#ping -c 3 208.67.222.222
#echo
ping -c 3 google.com
echo
ping -c 3 bing.com
echo
ping -c 3 amazon.com
echo
#curl --location --silent http://www.isup.me/google.com | grep "It.*just you"
#curl --location --silent http://www.isup.me/bing.com | grep "It.*just you"
#curl --location --silent http://www.isup.me/amazon.com | grep "It.*just you"
#curl --location --silent http://www.isup.me/ebay.com | grep "It.*just you"
echo
echo "Checking Msft NCSI ipv4:"
for i in {1..3}; do
curl --silent --max-time 30 --write-out " -- Took %{time_total} sec\n" http://www.msftncsi.com/ncsi.txt
done
echo
echo "Checking Msft NCSI ipv6:"
for i in {1..3}; do
curl --silent --max-time 30 --write-out " -- Took %{time_total} sec\n" http://ipv6.msftncsi.com/ncsi.txt
done
echo
traceroute -w 1 -q 1 -n 4.2.2.2
#traceroute -w 1 -q 1 -n 208.67.222.222
#traceroute -w 1 -q 1 -n google.com
#traceroute -w 1 -q 1 -n msftncsi.com
echo
echo "Local IP:"
ifconfig | grep inet
echo
echo "Public IP:"
curl --silent ifconfig.me
echo
echo
TIMESTAMP=`date "+%y%m%d_%H%M%S"` #add %3N to get milliseconds
echo "$TIMESTAMP"
ENDTIME=$SECONDS
echo "Took $(( ENDTIME - BEGTIME )) seconds"
TIMEOUT=$(( 3 * 60 ))
read -t $TIMEOUT -p "Hit ENTER or wait $TIMEOUT seconds..."
echo
done | tee -a $LOGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment