Gathering network information and connectivity diagnostics
In this section, we are going to test IPv4's connectivity and write scripts for it.
Getting ready
Besides having a terminal open, we need to remember a few concepts:
- The If..Else condition case in shell scripting
- IP address of the device
curl
command must be installed (you can install it by using the following command:Âsudo apt install curl
)
The purpose of this section is to show you how you can check network connectivity.
How to do it...
- 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/null then 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]...