检测局域网主机状态

#!/bin/bash
#
#********************************************************************
#Author:               betterman
#QQ:                  1602604658
#Date:                2020-05-15
#FileName:            test_local_ip.sh
#URL:                 https://www.cnblogs.com/betterquan/
#Description:         The test script
#Copyright (C):      2020 All rights reserved
#********************************************************************
#

log_flag=`date "+%F-%T"`
log_name=/tmp/test_local_ip_result_${log_flag}.txt

for i in {200..254}
do
    IP=192.168.111.$i
    #尝试ping三次,每次等一秒
    ping -c 3 -w 3 $IP &>/dev/null                                                                     
    if [ $? -ne 0 ]
        then
            #同时输出到文件当中保存
            echo "$IP is off" |tee -a $log_name
    else
            echo "$IP is on" |tee -a $log_name
    fi
done

 

posted @ 2020-05-15 21:54  linux——quan  阅读(254)  评论(0编辑  收藏  举报