您的位置:首页 > 运维架构 > Shell

Linux ping一段IP地址范围的一个简单的shell

2012-05-08 17:45 651 查看
找到了一个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, dooit.lee@gmail.com
# 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

[b][b][b]done[/b][/b][/b]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: