首页 > 代码库 > linux下检测局域网在线主机

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



本文出自 “勤能补拙” 博客,请务必保留此出处http://echoroot.blog.51cto.com/11804540/1923578

linux下检测局域网在线主机