ping主机脚本

#!/bin/bash
#ping 

net='172.16.1'
uphosts=0
downhosts=0

for i in {1..254};do
  ping -c 1 -w 1 ${net}.${i} &> /dev/null
  if [ $? -eq 0 ];then
    echo "${net}.${i} is up."
    let uphosts++
  else
    echo "${net}.${i} is down."
    let downhosts++
  fi
done

echo "Up hosts:$uphosts"
echo "Down hosts:$downhosts"
~                                      

  

posted @ 2017-10-12 15:39  BigZero  阅读(386)  评论(0编辑  收藏  举报