Linux ping一段IP地址範圍的一個簡單的shell

找到了一個linux下ping 一IP地址段內網絡連通性的腳本。
假如腳本名稱爲pingip.sh 使用方式爲:
#./pingip.sh 1 255
表示ping 192.168.0.1----255段內的設備。
 
#!/bin/bash
#
# Purpose: This program uses for detect a range of IP online or not
# print OK if online, otherwise print Failed
#
# Written by Dooit, [email protected]
# Tue Feb 22, 2011
#

if [ $# -lt 2 -o $1 -gt $2 ]; then
echo "Usage: `basename $0` <begin> <end>"
exit 1
fi

echo "This program uses for detecting a range of IPs online or not"
echo "NOTE: This program only ping for 192.168.0.0 network"

network="192.168.0."

# ping each ip in sequence between $1 and $2
for ip in $(seq $1 $2)
do
# sed and awk ping situation if you want
if ping -c 1 ${network}${ip} >& /dev/null
then
echo "${network}${ip}: OK"
else
echo "${network}${ip}: Failed"
fi

done

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章