- Open a terminal and create the test_ipv4.sh script:
if ping -q -c 1 -W 1 8.8.8.8 >/dev/null; then echo "IPv4 is up"else echo "IPv4 is down"fi
- Now, to test IP connectivity and DNS, create a script called test_ip_dns.sh:
if ping -q -c 1 -W 1 google.com >/dev/nullthen echo "The network is up"else echo "The network is down"fi
- Lastly, create a script called test_web.sh to test web connectivity:
case "$(curl -s --max-time 2 -I http://google.com | sed 's/^[^ ]* *\([0-9]\).*/\1/; 1q')" in [23]) echo "HTTP connectivity is up";; 5) echo "The web proxy won't let us through";; *) echo "The network is down or very slow";;esac