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

有時候想看看網(wǎng)段中有哪些IP被用了,可以用這個快速ping做一個初步的判斷??梢宰约褐付y試IP網(wǎng)段,并將測試結(jié)果整理排序到文件。

創(chuàng)新互聯(lián)建站是一家企業(yè)級云計算解決方案提供商,超15年IDC數(shù)據(jù)中心運(yùn)營經(jīng)驗(yàn)。主營GPU顯卡服務(wù)器,站群服務(wù)器,遂寧聯(lián)通機(jī)房,海外高防服務(wù)器,成都機(jī)柜租用,動態(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!"

文章標(biāo)題:shell腳本實(shí)現(xiàn)快速ping網(wǎng)段內(nèi)的IP地址
URL網(wǎng)址:http://muchs.cn/article6/ihiiog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)網(wǎng)站營銷企業(yè)建站、自適應(yīng)網(wǎng)站、品牌網(wǎng)站建設(shè)、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化