linux下检测局域网在线主机
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
测试结果:
[[email protected] /]# bash -n /tmp/pingCK.sh
[[email protected] /]# /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下检测局域网在线主机的主要内容,如果未能解决你的问题,请参考以下文章