Trying to troubleshoot an intermittent network problem? Just want to know if you ISP is dropping packets or going down altogether?
So many times I’ve search the ‘net for a simple network uptime script. I always wanted to know the exact time the network went down (and came back up) so that I could track down the cause of the problem. Here is a dead-simple script that will do just that:
#!/bin/bash ## connect_test.sh ## ## This script continually pings an IP address / hostname and reports *only* ## when it is unable to reach the destination. ## ## Example: ./connect_test.sh www.google.com if [[ $1 == "" ]]; then echo "Please provide an IP/host to ping" exit fi while [ true ]; do p=`ping -c 4 $1 > /dev/null 2>&1` if [[ $? != 0 ]]; then d=`date` echo "Unable to reach $1 at $d" sleep 1 fi done
It works best if you open up multiple terminal windows and try to connect to different portions of your network simultaneously. For example:
./connect_test.sh [my neighboring workstation] ./connect_test.sh [my gateway] ./connect_test.sh [my ISPs DNS] ./connect_test.sh [random domain - ie. google.com or yahoo.com]
This way, you can determine exactly where the failure is AND you have a record of the time it occurred. Hope that helps!
Post a Comment