To achieve ping a network segment of all the IP, and detect the network connection status is normal, many methods can be implemented, the following is a brief introduction of two, as follows:
Script 1
#!/bin/sh
# Ping Network segment all IPs
# 2012/02/05
Ip=1 #通过修改初值
while [$ip! = "254]; Do
#yes正常, no host does not exist or is not normal
Ping 192.168.0. $ip-C 2-w 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 Network segment all IPs
# 2012/02/05
Ip= "192.168.0."
For i in ' SEQ 1 254 '
Do
Ping-c 2 $ip $i-w 2 | Grep-q ' ttl= ' && echo ' $ip $i Yes ' | | echo "$ip $i No"
#yes正常, no host does not exist or is not normal
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
Shell detects network status scripts for entire network segment IP by pinging