使用until和while分别实现192.168.0.0/24 网段内,地址是否能够ping通,弱ping通则输出”success!”,若ping不通则输出”fail!”
while
#!/bin/bash
#
declare -i i=1
while [ $i -le 254 ];do
if ping -W 1 -c 1 192.168.0.$1 &> /dev/null;then
echo "host 192.168.0.$i is alive."
else
echo "host 192.168.0.$i is down."
fi
let i++
done
until
#!/bin/bash
#
declare -i i=1
until [ $i -gt 254 ];do
if ping -W 1 -c 1 192.168.0.$1 &> /dev/null;then
echo "host 192.168.0.$i is alive."
else
echo "host 192.168.0.$i is down."
fi
let i++
done