1 #!/bin/bash 2 PREFIX=192.168.116 3 num=1 4 while [ "$num" -lt "255" ]; do 5 echo -en "Pinging ${PREFIX}.${num}..." 6 ping -c1 -w1 -t5 ${PREFIX}.${num} >/dev/null 2>&1 7 if [ "$?" -eq "0" ]; then 8 echo "OK" && echo “${PREFIX}.${num}” >>ok.txt 9 else 10 echo "Failed" && echo “${PREFIX}.${num}” >>failed.txt 11 fi 12 let num=$num+1 13 done 14
测试完之后可以ping通的IP存放在ok.txt文件中,ping不同的IP村放在failed.txt文件中