Intra-enterprise network segment detects how many hosts live--shell scripts

Source: Internet
Author: User

Intra-enterprise network segment detects how many hosts are alive1) byPingLifeorder to achieve

Ping-c 1-w 1 IP

- C: indicates the numberof times , 1 is 1

- W: represents deadline, time out , in seconds,1 for 1 seconds.

Note: a) If one goes to ping to wait for a long time, so the use of multi-threaded in the background to perform B) if not multi-threading, there is a problem is that when running for the loop CTRL +c can only stop the current loop of that, stop after the next for loop, can not be returned, but also to open a A terminal to kill the process of the script, inconvenient, this can be used trap to solve C) if the results of the key word is "OK", the best lang=en to English, or in the future, the problem is not good row wrong, or in English, so the interception of things also convenient and then according to the above three. Make the following script: ... The entry level is not counted.
2) Writing Scripts

[[email protected] scripts] #cat check_hosts.sh#!/bin/bash./etc/rc.d/init.d/functionsping= "Ping-w1-c 1" ip= " 192.168.0. "#trap" echo "Bye-bye"; exit "2for i in ' seq 1254 ' do {$ping ${ip}${i} >/dev/null if [$?-eq 0];then Actio n "${ip}${i} ...."/bin/true >>true.txt Else Action "${ip}${i} ..."/bin/false >>false.txt fi}& ;d One
3) Execute the script

[[email protected]] #sh check_hosts.sh

4) Check the results after the operation

[Email protected]]# cat True.txt

192.168.0.13 ... [OK]

192.168.0.1 ... [OK]

192.168.0.56 ... [OK]

192.168.0.10 ... [OK]

[[Email protected]]#


This article is from the "Linux Advanced Ops Road" blog, so be sure to keep this source http://yulianhui.blog.51cto.com/10829691/1725766

Intra-enterprise network segment detects how many hosts live--shell scripts

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.