What would you suggest for reliable servers to ping for connectivity?
If the tunnel drops, the vpnstatus (aka vpnwatch) script kindly written
by Marek Novotny drops all sensitive apps, which lets me know that the
tunnel dropped.
However, if the tunnel is still up, but, for whatever reason, connectivity
is lost, then I don't find this out for minutes simply because the only
way I notice that there is no connectivity is that network commands fail
to run (e.g., a ping to anywhere would fail when the connectivity is lost).
So, I hacked out this "vpnping" script today, just to test connectivity
at random intervals to random servers, popping up a notification only
when connectivity is lost.
The current list of servers was taken from a list of public DNS servers
that I found on the net, but I would like to expand the list of potential
servers to test (to spread out the load).
My question is what *list* of reliable servers would you use to test
the connectivity to?
Here's the version 0.01 script that tests for connectivity.
#!/bin/bash
# vpnping.sh v0.01 pops up a notification if connectivity is lost
# Define variables:
maxDelay=10 # max seconds for random delay between pings
minDelay=2 # min secondsf or random delay between pings
timeout=2300 # fping timeout is in milliseconds (ping TTL is in seconds)
# Select a random server to ping for connectivity
# Code structure courtesy of Marek Novotny
# WIP: Need a better list of reliable servers to ping!
randomServer()
{
pingArray=(
"119.81.242.146" # Korea ns1.hk.dns.opennic.glue
"172.81.176.146" #
ns1.tor.ca
"190.10.8.128" #
ns1.cr
"192.99.240.129" #
ns1.mtr.ca
"193.183.98.154" # Korea ns1.it.dns.opennic.glue
"195.46.39.39" # SafeDNS public dns server
"195.46.39.40" # SafeDNS public dns server
"208.67.220.220" # OpenDNS Home4 public dns server
"208.67.222.222" # OpenDNS Home4 public dns server
"209.244.0.3" # Level3 public dns server
"209.244.0.4" # Level3 public dns server
"216.146.35.35" # Dyn public dns server
"216.146.36.36" # Dyn public dns server
"37.235.1.174" # FreeDNS public dns server
"37.235.1.177" # FreeDNS public dns server
"4.2.2.1" # Verizon public dns server
"4.2.2.2" # Verizon public dns server
"4.2.2.3" # Verizon public dns server
"4.2.2.4" # Verizon public dns server
"4.2.2.5" # Verizon public dns server
"4.2.2.6" # Verizon public dns server
"50.116.23.211" #
ns19.tx.us
"50.116.23.211" # OpenNIC dns server
"5.9.49.12" # Korea ns24.de.dns.opennic.glue
"79.133.43.124" # Korea ns3.vie.at.dns.opennic.glue
"8.20.247.20" # Comodo Secure DNS public dns server
"8.26.56.26" # Comodo Secure DNS public dns server
"8.8.4.4" # Google public dns server
"8.8.8.8" # Google public dns server
)
pingRange=$((${#pingArray[@]} - 1))
i=$RANDOM
let "i %= $pingRange"
pingIP=${pingArray[$i]}
# echo "pingIP set to $pingIP"
}
# Set up the display for the xmessage:
setupDisplay()
{
if [[ -z "$DISPLAY" ]]; then
DISPLAY=':0'
fi
}
setupDisplay
# Pop up a message if connectivity is lost:
# WIP: Do something with the buttons or remove them.
sendMessage()
{
ans=$(xmessage -display $DISPLAY -fg black -bg red \
-title "Connectivity lost!" -geom +60+30 \
-buttons yes,no -default yes "$1")
}
# Loop continuously testing random site connectivity at random intervals
while true; do # continue until a kill or Ctrl+C occurs
randomServer # select a random server to ping
sleep $[ ( $RANDOM % $maxDelay ) + $minDelay ]s # wait a random min-to-max second delay
fping -c1 -t${timeout} $pingIP 2>/dev/null 1>/dev/null # ping the server
if [ $? -ne 0 ]; then # if the ping failed within the timeout, then send a message
sendMessage "Ping $pingIP failed on $(date)"
fi
done
exit 0
## End ##