溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

shell腳本實(shí)現(xiàn)快速ping網(wǎng)段內(nèi)的IP地址

發(fā)布時(shí)間:2020-07-28 13:01:25 來(lái)源:網(wǎng)絡(luò) 閱讀:863 作者:tutor 欄目:系統(tǒng)運(yùn)維

有時(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!"


向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI