ping一堆机器的二种方法(shell或fping)
cat ip.sh #!/bin/bash #-------------------------------------------------- #Created:2015-04-28 #Author:jimmygong #Mail:[email protected] #Function:ping #Version:1.0 #-------------------------------------------------- set -o nounset ipfile=~/iplist.txt pinglog=~/ping.log pinglog2=~/ping.log2 [[ -e $ipfile ]] || exit 1 [[ -e $pinglog ]] && `> $pinglog` function pingfc () { touch $pinglog i=1 while read ipline do ( packet=`ping -s 100 -f -c 10 -q $ipline|awk /transmitted/|awk ‘{print $6}‘` echo "$ipline $packet" >> $pinglog )& [[ $i%10 -eq 0 ]] && wait done < $ipfile wait grep -v " 0%" $pinglog > $pinglog2 2>&1 } pingfc exit 0 ==================================说明============================================ bash ip.sh 执行结果 cat ping.log 10.1.1.101 0% 10.1.1.102 0% 10.1.1.104 0% 10.1.1.105 0% 10.1.1.103 100% cat iplist.txt 10.1.1.101 10.1.1.102 10.1.1.103 10.1.1.104 10.1.1.105 -f 极限检测。大量且快速地送网络封包给一台机器看它的回应。 -f Flood ping. For every ECHO_REQUEST sent a period ?..?..is printed, while for ever ECHO_REPLY received a backspace is printed. This provides a rapid display of how many packets are being dropped. If interval is not given, it sets interval to zero and outputs packets as fast as they come back or one hundred times per second, whichever is more. Only the super-user may use this option with zero interval. -s 字节数指定发送的数据字节数预设值是56加上8字节的ICMP头一共是64ICMP数据字节。 Specifies the number of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data. -c 数目在发送指定数目的包后停止。 -c count Stop after sending count ECHO_REQUEST packets. With deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires. -q 不显示任何传送封包的信息只显示最后的结果。 -q Quiet output. Nothing is displayed except the summary lines at startup time and when finished. 二、需要安装fping命令(apt-get -y install fping --force-yes或yum -y install fping) fping - sends ICMP ECHO_REQUEST packets to network hosts fping -ef /root/iplist.txt >ping.log 2>&1 ==================================说明============================================ 执行结果 cat ping.log 10.1.1.101 is alive (0.66 ms) 10.1.1.102 is alive (1.22 ms) 10.1.1.104 is alive (1.28 ms) 10.1.1.105 is alive (1.26 ms) 10.1.1.103 is unreachable cat iplist.txt 10.1.1.101 10.1.1.102 10.1.1.103 10.1.1.104 10.1.1.105 -f Read list of targets from a file. -e Show elapsed (round-trip) time of packets
本文出自 “7928217” 博客,请务必保留此出处http://7938217.blog.51cto.com/7928217/1639753
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。