Implemented using While,until and for (two forms) loops respectively.
Requirements: Test the host online via the ping command,
If online, "IP is Up", where the IP is to be replaced with a real IP address, and displayed in green;
If you are not on the line, the IP is down, where the IP is changed to a real IP address and displayed in red;
#!/bin/bash
#
For I in {200..201}; Do
Ping-c 1-w 1 10.109.131. $I &>/dev/null
[$?-eq 0] && echo-e "\033[36m110.109.131. $I is up\033[0m" | | Echo-e "\033[35m110.109.131. $I is down\033[0m"
Done
DECLARE j=215
While [$J-lt 217];d O
Ping-c 1-w 1 10.109.131. $J &>/dev/null
Pp=$?
[$PP-eq 0] && echo "110.109.131 $J is up" | | echo "110.109.131. $J is Down"
Let J + +
Done
DECLARE k=220
Until [$K-gt 222];d o
Ping-c 1-w 1 110.109.132. $K &>/dev/null
P3=$?
[$P 3-eq 0] && echo-e "\033[36m110.109.132. $K is up\033[0m" | | Echo-e "\033[35m110.109.132. $K is down\033[0m"
Let k++
Done
[Email protected] ~]#./ping.sh
110.109.131.200 is up
110.109.131.201 is up
110.109.131.215 is down
110.109.131.216 is down
110.109.132.220 is up
110.109.132.221 is down
110.109.132.222 is up
Linux command: AUTO PING