Intra-enterprise network segment detects how many hosts survive--shell script Pass (ii)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.