read -p "Please input two numbers between 1 and 255,The first must smaller than the second:" A B
echo ""> /tmp/host_state
while [ $A -le $B ];
do
HOST="192.168.0.$A"
ping -c1 -w2 $HOST >/dev/null && ( echo "The host $HOST is UP." |tee -a /tmp/host_state )||( echo "The host $HOST is DOWN."|tee -a /tmp/host_state )
A=$[$A+1]
done
sed -i 's/\(.*DOWN\.$\)/#\1/g' /tmp/host_state
echo "host online :`grep UP /tmp/host_state|wc -l`"
echo "host offline :`grep DOWN /tmp/host_state|wc -l`"
![扫描192.168.0网段内的主机的在线状态_职场](https://s2.51cto.com/attachment/201105/205714789.jpg?x-oss-process=image/resize,m_fixed,w_1184)