To Ping all IP addresses in a CIDR Block and check whether the network connection status is normal, you can use many methods. The following describes two methods:
Script 1
#! /Bin/sh
# Ping all IP addresses of a CIDR Block
#2012/02/05
Ip = 1 # modifying the Initial Value
While [$ ip! = "254]; do
# Yes: The no host does not exist or is abnormal.
Ping 192.168.0. $ ip-c 2 | grep-q "ttl =" & echo "192.168.0. $ ip yes" | echo "192.168.0. $ ip no"
Ip = 'expr "$ ip" "+" "1 "'
Done
Output result:
192.168.0.1 yes
192.168.0.2 no
192.168.0.3 no
192.168.0.4 no
192.168.0.5 yes
192.168.0.6 no
192.168.0.7 yes
...
Script 2
#! /Bin/sh
# Ping all IP addresses of a CIDR Block
#2012/02/05
Ip = "192.168.0 ."
For I in 'seq 1 254'
Do
Ping-c 2 $ ip $ I | grep-q 'ttl = '& echo "$ ip $ I yes" | echo "$ ip $ I no"
# Yes: The no host does not exist or is abnormal.
Done
Output result:
192.168.0.1 yes
192.168.0.2 no
192.168.0.3 no
192.168.0.4 no
192.168.0.5 yes
192.168.0.6 no
192.168.0.7 yes
...
If you have a better implementation method, you can leave a message ~