linux下检测局域网在线主机

用户输入一个启始主机和结束主机,检测局域网这个范围内的主机在线状态

pingCK.sh:

#!/bin/bash

#study

#v0.0.2

#ping 192.168.21.1 - 192.168.21.254

read -p "enter start host:" snum

read -p "enter end host:" enum

for i in $(seq $snum 1 $enum);do

ping -c 1 -t 1 192.168.21.$i > /tmp/res

grep ttl /tmp/res>/tmp/rus

        if  [ `wc -l /tmp/rus |awk '{print $1}'`  = 0 ];then

        echo "21.$i is off"

        else

        echo "21.$i is online"

        fi

done


测试结果:

[root@localhost /]# bash -n /tmp/pingCK.sh 

[root@localhost /]# /tmp/pingCK.sh 

enter start host:128

enter end host:135

21.128 is off

21.129 is off

21.130 is off

21.131 is off

21.132 is off

21.133 is online

21.134 is off

21.135 is off

done





      本文转自echoroot 51CTO博客,原文链接:http://blog.51cto.com/echoroot/1923578,如需转载请自行联系原作者


上一篇:PDF文件阅读器迷你绿色纯净版3.4 和《电脑爱好者》2015年PDF 更新至18期


下一篇:OpenCV 实时人脸检测