有時(shí)候想看看網(wǎng)段中有哪些IP被用了,可以用這個(gè)快速ping做一個(gè)初步的判斷??梢宰约褐付y試IP網(wǎng)段,并將測試結(jié)果整理排序到文件。
創(chuàng)新互聯(lián)建站是一家企業(yè)級云計(jì)算解決方案提供商,超15年IDC數(shù)據(jù)中心運(yùn)營經(jīng)驗(yàn)。主營GPU顯卡服務(wù)器,站群服務(wù)器,遂寧聯(lián)通機(jī)房,海外高防服務(wù)器,成都機(jī)柜租用,動(dòng)態(tài)撥號VPS,海外云手機(jī),海外云服務(wù)器,海外服務(wù)器租用托管等。
#!/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 [y/n] ? "
? ? 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!"