1、while [root@node01 day4]# cat ping1.sh #!/bin/bash ip=1 while [ "$ip" != "254" ]; do ping -c 2 192.168.3.$ip |grep -q "ttl=" && echo "192.168.3.$ip yes" || echo "192.168.3.$i no" ip=`expr "$ip" "+" "1"` done 2、for else [root@node01 day4]# vi ping2.sh echo -n "i #!/bin/bash ip=192.168.3 for i in `seq 1 255` do ping -c 2 $ip.$i> /dev/null 2>&1 if [ `echo $?` -eq 0 ];then echo -n " $ip.$i is up " else echo -n " $ip.$i is down " fi done