through the ping command, test whether all hosts between 192.168.1.100 to 192.168.1.120 are online and, if online, "IP is up ." "where IP is swapped for a true IP address and is displayed in green, and if it is not, the IP isdown. "where The IP is to be swapped for a real IP address and displayed in red. requirements, respectively, using while,until and for (two kinds).
1, #!/bin/bash
#
For I in {100..120};d o
Ping-c 2-w 3 192.168.1. $I &>/dev/null
Retval=$?
If [$RETVAL-eq 0];then
Echo-e "\033[32m192.168.1. $I \033[0mis up."
Else
Echo-e "\033[31m192.168.1. $I \033[0m is down."
Fi
Done
2,#!/bin/bash
#
Fori ((i=100;i<=120;i++));d o
If Ping-c 2-w 3 192.168.1. $I &>/dev/null;then
Echo-e "\033[32m192.168.1. $I \033[0mis up."
Else
Echo-e "\033[31m192.168.1. $I \033[0mis down."
Fi
Done
3 , #!/bin/bash
#
Declare-i i=100
Declare-i sum=0
while[$I-ge 100-a $I-lt];d o
sum=$ (($I + 1))
Let i++
Ping-c 3-w 3 192.168.1. $sum &>/dev/null
Retval=$?
if[$RETVAL-eq 0];then
Echo-e "\033[32m192.168.1. $sum \033[0m is up."
Else
Echo-e "\033[31m192.168.1. $sum \033[0m is down."
Fi
Done
4 , #!/bin/bash
#
Declare-i i=100
Declare-i sum=0
until[$I-lt 100-o $I-gt 119];d o
sum=$ (($I + 1))
Let i++
If Ping-c 3-w 3 192.168.1. $sum &>/dev/null;then
Echo-e "\033[32m192.168.1. $sum \033[0m is up."
Else
Echo-e "\033[31m192.168.1. $sum \033[0m is down."
Fi
Done
This article is from the "LawLer" blog, make sure to keep this source http://10728233.blog.51cto.com/10718233/1695725
ping command Detection script