Intra-enterprise network segment detects how many hosts are alive
Preface: This script originally came from watching the network class Gou Qi 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0058.gif "alt=" J_0058.gif "/> The space release of the script, today revised a bit, feel very convenient.
Environment Introduction:
IP Address Segment |
External network |
Intranet |
10.0.0.0 |
Yes |
No |
172.16.1.0 |
No |
Yes |
1). scripting
[[email protected] oldboy20160103]# cat check_ hosts.sh #!/bin/bash#no.1 check functions [ ! -f /etc/ini.d/functions ] && source /etc/init.d/functions#no.2 judge $1[ $# -ne 1 ] && { echo "Usage: $0 ipaddr" exit 1} #no. 3ping= "ping -w1 -c 1" ip=$1#no.4for n in ' seq 10 ' do { $PING $1${n} &>/dev/null if [ $? -eq 0 ] then action "$1${n} is online " /bin/true else action "$1${n} is gone" /bin/false fi}done
2). Execute Script
[[email protected] oldboy20160103]# sh check_hosts.sh 10.0.0.10.0.0.1 is online [ OK ]10.0.0.2 is online [ OK ]10.0.0.3 is gone [ Failed]10.0.0.4 is gone [FAILED]10.0.0.5 is gone [FAILED]10.0.0.6 is gone [failed] 10.0.0.7 is online [ OK ]10.0.0.8 is online [ OK ]10.0.0.9 is gone [failed] 10.0.0.10 is gone &nbSp; [failed]
prompt: 10.0.0.1 is my NAT bridge address, and 10.0.0.1 is my NAT gateway address.
[[Email protected] oldboy20160103]# sh check_hosts.sh 172.16.1.172.16.1.1 is gone [FAILED]172.16.1.2 is gone [ failed]172.16.1.3 is gone [FAILED]172.16.1.4 is gone [failed] 172.16.1.5 is gone [FAILED]172.16.1.6 is gone [FAILED]172.16.1.7 is online [ ok ]172.16.1.8 is online [ OK ]172.16.1.9 is gone [failed] 172.16.1.10 is gone [failed]
This article is from the "Linux Advanced Ops Road" blog, so be sure to keep this source http://yulianhui.blog.51cto.com/10829691/1732440
Intra-enterprise network segment detects how many hosts survive--shell script Pass (ii)