Shell script to realize IP address in Fast ping Network Segment
Sometimes if you want to see which IP is used in the network segment, you can use this fast ping to make a preliminary judgment. You can specify your own test IP segment and sort the test results into files.
#! / bin/bash
# V1.0 2019-09-10
# Ping test shell script by tutor
Clear
> ip-up.txt
> ip-down.txt
While true
Do
Read-p "Please input the ip segment for ping test (like 192.168.100):" segment
If [- z $segment]; then
Segment= "192.168.100"
Fi
Echo-n "the ip segment is ${segment}, are you sure to continue [yzone]?"
Read action
If [- z $action]; then
Break
Fi
If ["$action" = "y"]; then
Break
Fi
Done
Echo "ping test is ready to run!"
For i in {1..254}
Do
{
Ping-c2-W1 ${segment}. ${I} & > / dev/null
If [$?-eq 0]; then
Echo "${segment}. $i is up" & > / dev/null > > ip-up.txt
Else
Echo "${segment}. $i is down" & > / dev/null > > ip-down.txt
Fi
} &
Done
Wait
Sort-n-k 4-t. Ip-up.txt-o ip-up.txt
Cat ip-up.txt
Sort-n-k 4-t. Ip-down.txt-o ip-down.txt
Cat ip-down.txt
Echo "ping test are finished!"