Ping N个IP测试网络连通性

时间:2024-10-28 12:34:20

#-----------------------Smokeping移动节点-------------------#
#! /bin/bash
echo "------------- Stating test mobile mode------------ "
for i in `cat mobile`
do
ping=`ping -c 1 $i|grep loss|awk '{print $6}'|awk -F "%" '{print $1}'`
if [ $ping -eq 100 ];then
echo ping $i is [fail]
else
echo ping $i is [OK]
fi
done
echo "-------------- End test mobile mode--------------- "
#-----------------------Smokeping移动节点-------------------#

#! /bin/bash

for i in `cat smokeping`  #这个是逐个读取smokeping文件里的ip
do
ping=`ping -c 1 $i|grep loss|awk '{print $6}'|awk -F "%" '{print $1}'`
#上面一行是对读出来的ip ping一次,看是否ping通。并取出loss的百分比的值 也就是掉包的值 ,看是否掉包
if [ $ping -eq 100  ];then #比较一下,看掉包的值是不是100,如果是100就是全部掉包,那就是没ping通,那就显示 ping ip fail,如果不等于100的话,就ping通了,就显示 Ping ip OK
echo ping $i is [fail]
else
echo ping $i is [OK]
fi