shell脚本实现快速ping网段内的IP地址
有时候想看看网段中有哪些IP被用了,可以用这个快速ping做一个初步的判断。可以自己指定测试IP网段,并将测试结果整理排序到文件。
创新互联建站是一家企业级云计算解决方案提供商,超15年IDC数据中心运营经验。主营GPU显卡服务器,站群服务器,遂宁联通机房,海外高防服务器,成都机柜租用,动态拨号VPS,海外云手机,海外云服务器,海外服务器租用托管等。
#!/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!"
当前文章:shell脚本实现快速ping网段内的IP地址
分享URL:http://scyanting.com/article/ihiiog.html