Sometimes segment want to see what IP is used, you can use this to quickly make a preliminary judge ping. You can specify your own IP network segment test, the test result to finish sorting 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"
be
echo -n "the ip segment is ${segment} , are you sure to continue [y/n] ? "
read action
if [ -z $action ] ; then
break
be
if [ "$action" = "y" ]; then
break
be
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
be
}&
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!"