#通过ping命令测试192.168.1段的所有主机是否在线,如果在线就显示is up并显示蓝色,如果不在线就显示is down。
#!/bin/bash #Program Description: #Author: Created by ctu_lzq #Date: 2018/11/15 net="192.168.1." for ((i=1;i<=254;i++)); do ping -c1 $net$i > /dev/null 2>&1 if [ $? -eq 0 ];then echo -e "\033[34m$net$i is up \033[0m" else echo "$net$i is down" fi done