[Shell] detects network status scripts for entire network segment IP by pinging

Source: Internet
Author: User
Tags ping network

To achieve ping a network segment of all the IP, and detect the network connection status is normal, many methods can be implemented, the following is a brief introduction of two, as follows:
Script 1
#!/bin/sh
# Ping Network segment all IPs
# 2012/02/05
Ip=1 #通过修改初值
while [$ip! = "254]; Do
#yes正常, no host does not exist or is not normal
Ping 192.168.0. $ip-C 2 | Grep-q "ttl=" && echo "192.168.0. $ip Yes" | | echo "192.168.0. $ip No"
ip= ' expr ' $ip "" + "" 1 "
Done

Output Result:
192.168.0.1 Yes
192.168.0.2 No
192.168.0.3 No
192.168.0.4 No
192.168.0.5 Yes
192.168.0.6 No
192.168.0.7 Yes
...

Script 2
#!/bin/sh
# Ping Network segment all IPs
# 2012/02/05
Ip= "192.168.0."
For i in ' SEQ 1 254 '
Do
Ping-c 2 $ip $i | Grep-q ' ttl= ' && echo ' $ip $i Yes ' | | echo "$ip $i No"
#yes正常, no host does not exist or is not normal
Done

Output Result:
192.168.0.1 Yes
192.168.0.2 No
192.168.0.3 No
192.168.0.4 No
192.168.0.5 Yes
192.168.0.6 No
192.168.0.7 Yes
...

If you have a better way to achieve, you can give me a message ~

[Shell] detects network status scripts for entire network segment IP by pinging

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.