Linux shell checks whether the Intranet ip address is alive

Source: Internet
Author: User
In linux, shell commands can implement almost all web management and task functions. Let's take a look at an example of how linux shell checks whether Intranet ip addresses are alive, I hope this article will help you.

Sometimes I want to find an ip address at home for testing on the virtual machine, but I don't remember the ip addresses that are in use and those that are not in use (don't say you remember them all, okay, I admit that I am old), so I wrote a shell script to detect it for your convenience.
Script content:

#! /Bin/bash
# By rocdk890
# Check the network is online
Read-p "Enter your network segment (example 192.168.1.):" ip_num
Echo "Please wait ..."
For I in 'seq 1 254'
Do
Ping-c 2-W 1 $ ip_num $ I>/dev/null
If [$? -Eq 0]; then
Echo "echo $ ip_num $ I is up"
Echo $ ip_num $ I is up> ip_yes.txt
Else
Echo "echo $ ip_num $ I is down"
Echo $ ip_num $ I is down> ip_no.txt
Fi
Done
Exit 0

This script allows you to enter your own CIDR Block for detection without modifying the script, as shown in figure

In the figure, I only detected 10 ip addresses.

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.