批量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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM