批量ping IP地址命令测试是否通
Posted compy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量ping IP地址命令测试是否通相关的知识,希望对你有一定的参考价值。
批量ping IP地址命令测试是否通
#!/bin/bash
#--------------------------------------------------------------------------------------------------
echo -e " "
echo -e " ==============================================="
echo -e "| Thanks for using this script! |"
echo -e " ==============================================="
echo -e "#***********************************************#"
echo -e "# ___ ___ _ __ ___ _ __ _ _ #"
echo -e "# / __/ _ \| ‘_| | \| |_ \| | | | #"
echo -e "# | (_| (_) | | | | | | |_) | |_| | #"
echo -e "# \___\___/|_| |_| |_| .__/ \__, | #"
echo -e "# |_| |___/ #"
echo -e "#-----------------------------------------------#"
echo -e "# #"
echo -e "# Author: compy QQ: 2071959367 #"
echo -e "# #"
echo -e "#***********************************************#"
echo -e " "
#--------------------------------------------------------------------------------------------------
#System environment variables.
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#--------------------------------------------------------------------------------------------------
echo "=================================英文注释========================================="
echo -e " This script determines whether the IP address is Ping,\n and the IP of Ping is stored in the ping.tong file in the current directory.\n The Ping IP is stored in the ping.notong file under the current directory."
echo "================================================================================"
echo "=================================中文注释========================================="
echo -e "此脚本为判断IP地址是否ping通,\nping通的IP存放在当前目录下的ping.tong文件中,\nping不通的IP存放在当前目录下的ping.notong文件中."
echo "================================================================================"
echo " "
if [ -z $1 ]
then
echo "Please enter the file name(eg:/home/eg.txt):"
read lu
else
lu=$1
fi
rq=`date +%G%m%d%k%m%S`
tar -zcf ip_ping_${rq}.tar.gz ip_ping
rm -rf ip_ping/
mkdir -p ip_ping
ULIST=$(cat $lu)
for UNAME in $ULIST
do
echo $UNAME >> a.txtlog
ping $UNAME -c 3 -i 0.01 >> ip_ping/$UNAME
#ping $UNAME -c 10 -i 0.01
number=`cat ip_ping/$UNAME | grep transmitted | awk -F "," ‘{print $3}‘ | awk -F " " ‘{print $1}‘ | awk -F "%" ‘{print $1}‘`
echo "$UNAME $number" >> ./ip_txt.txt
if [ $number = 100 ]
then
echo "$UNAME ping不通" >>./ping.tong
echo "$UNAME ping不通"
else
echo "$UNAME ping通" >>./ping.notong
echo "$UNAME ping通"
fi
rm -rf ip_ping/$UNAME
done
源码文件链接:http://pan.baidu.com/s/1c20B8XE
作者:compy 更新日期:2017-07-30 23:07 QQ:2071959367
以上是关于批量ping IP地址命令测试是否通的主要内容,如果未能解决你的问题,请参考以下文章
Linux脚本练习之script017-接受一个主机的 IPv4 地址作为参数,测试是否可连通。如果能够 ping 通,则提示用户“该 IP 地址可访问”。
shell脚本从命令行输入ip或读取文件ping Ip地址是否通ping.sh