標籤:shell fping
cat ip.sh#!/bin/bash#-------------------------------------------------- #Created:2015-04-28#Author:jimmygong#Mail:[email protected]#Function:ping#Version:1.0#--------------------------------------------------set -o nounsetipfile=~/iplist.txtpinglog=~/ping.logpinglog2=~/ping.log2[[ -e $ipfile ]] || exit 1[[ -e $pinglog ]] && `> $pinglog`function pingfc () {touch $pinglogi=1while read iplinedo ( packet=`ping -s 100 -f -c 10 -q $ipline|awk /transmitted/|awk ‘{print $6}‘` echo "$ipline $packet" >> $pinglog )& [[ $i%10 -eq 0 ]] && waitdone < $ipfilewaitgrep -v " 0%" $pinglog > $pinglog2 2>&1}pingfcexit 0==================================說明============================================bash ip.sh執行結果cat ping.log10.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.txt10.1.1.10110.1.1.10210.1.1.10310.1.1.10410.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 howmany 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 countStop 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 hostsfping -ef /root/iplist.txt >ping.log 2>&1==================================說明============================================執行結果cat ping.log10.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 unreachablecat iplist.txt10.1.1.10110.1.1.10210.1.1.10310.1.1.10410.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
ping一堆機器的二種方法(shell或fping)