您好,登錄后才能下訂單哦!
有時(shí)候想看看網(wǎng)段中有哪些IP被用了,可以用這個(gè)快速ping做一個(gè)初步的判斷。可以自己指定測(cè)試IP網(wǎng)段,并將測(cè)試結(jié)果整理排序到文件。
#!/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!"
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。