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.