shell脚本检查网段内的ip是否可以被ping通

while版本

#!/bin/bash
i=1
while [ $I -le 254 ]
do
  ping -c2 -i0.3 -W1 172.24.132.$i &>/dev/null
  if [ $? -eq 0 ]; then
    echo "172.24.132.$i is up"
  else
    echo "172.24.132.$i is down"
  fi
  let i++
done

for版本

#!/bin/bash
for i in {1..254}
do
  ping -c2 -i0.3 -W1 172.24.132.$i &>/dev/null
  if [ $? -eq 0 ]; then
    echo "172.24.132.$i is up"
  else
    echo "172.24.132.$i is down"
  fi
done

 

多进程版本

#!/bin/bash
testping(){
ping -c2 -i0.3 -W1 $1 $>/dev/null
if [ $? -eq 0 ]; then
echo "$1 is up"
else
echo "$1 is down"
fi
}

for i in {1..254}
do
  testping 172.24.132.$i &
done

 

posted @ 2018-11-30 14:41  初期网工  阅读(3698)  评论(0编辑  收藏  举报