シェルスクリプトを使用したネットワークトラフィックアナライザ

シェルスクリプトを使用したネットワークトラフィックアナライザ

同時にpingしてttlを取得し、ネットワーク上のIPアドレスセットをテキストファイルの2つの列に保存する方法やスクリプトはありますか?ロードバランシンググラフに役立つシェルスクリプトを作成したいと思います。私はnmap、dig、およびfpingコマンドを試しましたが、要件に応じて目的の出力を取得できませんでした。 CentOs 6.5 作業中

ベストアンサー1

私が質問を理解したら、この簡単なスクリプトがあなたに役立ちます。

#!/bin/sh

# List of IP or domain names
LIST="192.168.1.101 192.168.1.110 192.168.1.254 192.168.1.250"

# Where to store the data?
outFile="${HOME}/network-test"

# raw data per IP
raw=""

# Clear the result each time or not? This will clear it each time
echo -n > "${outFile}"

for ip in $LIST
do
    raw=`ping -c 1 -t 255 "${ip}" | grep ttl | awk -F" |ttl=" '{ print $1 }'`
    if [ "$raw" != "" ]
    then
        echo "${ip} ${raw}" >> $outFile
    else
        echo "${ip} no-ping" >> $outFile
    fi
done

cat $outFile

exit

表示内容は次のようになります。

192.168.1.101 64
192.168.1.110 64
192.168.1.254 64
192.168.1.250 no-ping

おすすめ記事