Linux shell脚本 检测内网中存活主机

作者:hack1990 时间:12-05-14 阅读数:520人阅读

 #!/bin/bash
# Simple SHELL script for Linux and UNIX system monitoring with
# ping command
# code by robert
for ((a=1;a<=255;a++));do
HOSTS="192.168.132.$a"
COUNT=1
for myhost in $HOSTS
do
count=$(ping -c $COUNT $myhost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then # 100% failue
echo "$myhost is down (ping failed)"
else
echo "$myhost is up"
fi
done
done
 

发表评论