In the default mode, if a target replies, it is noted and removed from the list of targets to check; if a target does not respond within a certain time limit and/or retry limit it is designated as unreachable. fping also supports sending a specified number of pings to a target, or looping indefinitely (as in ping ).
Unlike ping , fping is meant to be used in scripts, so its output is designed to be easy to parse.
#!/usr/local/bin/perl require 'open2.pl'; $MAILTO = "root"; $pid = &open2("OUTPUT","INPUT","/usr/local/bin/fping -u"); @check=("slapshot","foo","foobar"); foreach(@check) { print INPUT "$_\\n"; } close(INPUT); @output=<OUTPUT>; if ($#output != -1) { chop($date=`date`); open(MAIL,"|mail -s 'unreachable systems' $MAILTO"); print MAIL "\\nThe following systems are unreachable as of: $date\\n\\n"; print MAIL @output; close MAIL; } .ni Another good example is when you want to perform an action only on hosts that are currently reachable.#!/usr/local/bin/perl $hosts_to_backup = `cat /etc/hosts.backup | fping -a`; foreach $host (split(/\\n/,$hosts_to_backup)) { # do it } .niThe following is an output example: % fping a.b.com x.y.z.net 192.168.0.1 192.168.0.3
a.b.com is alive x.y.z.net is alive 192.168.0.1 is alive 192.168.0.3 is aliveThe following is an output example using the '-a' option: % fping -a a.b.com x.y.z.net 192.168.0.1 192.168.0.3
a.b.com x.y.z.net 192.168.0.1 192.168.0.3The following is an output example using the '-c' option: \fb% fping -c 3 a.b.com x.y.z.net 192.168.0.1
a.b.com : [0], 84 bytes, 51.1 ms (51.1 avg, 0% loss) 192.168.0.1 : [0], 84 bytes, 0.08 ms (0.08 avg, 0% loss) [<- 192.168.0.4] x.y.z.net : [0], 84 bytes, 70.6 ms (70.6 avg, 0% loss) a.b.com : [1], 84 bytes, 60.9 ms (56.0 avg, 0% loss) 192.168.0.1 : [1], 84 bytes, 0.09 ms (0.08 avg, 0% loss) [<- 192.168.0.4] a.b.com : [2], 84 bytes, 40.6 ms (50.9 avg, 0% loss) 192.168.0.1 : [2], 84 bytes, 0.11 ms (0.09 avg, 0% loss) [<- 192.168.0.4] x.y.z.net : [2], 84 bytes, 68.8 ms (69.7 avg, 33% loss) a.b.com : xmt/rcv/%loss = 3/3/0%, min/avg/max = 40.6/50.9/60.9 x.y.z.net : xmt/rcv/%loss = 3/2/33%, min/avg/max = 68.8/69.7/70.6 192.168.0.1 : xmt/rcv/%loss = 3/3/0%, min/avg/max = 0.08/0.09/0.11The following is an output example using the '-C' option: \fb% fping -C 3 a.b.com x.y.z.net 192.168.0.1
a.b.com : [0], 84 bytes, 41.7 ms (41.7 avg, 0% loss) x.y.z.net : [0], 84 bytes, 66.6 ms (66.6 avg, 0% loss) a.b.com : [1], 84 bytes, 50.7 ms (46.2 avg, 0% loss) x.y.z.net : [1], 84 bytes, 62.6 ms (64.6 avg, 0% loss) a.b.com : [2], 84 bytes, 44.9 ms (45.8 avg, 0% loss) x.y.z.net : [2], 84 bytes, 69.5 ms (66.2 avg, 0% loss) a.b.com : 41.74 50.72 44.94 x.y.z.net : 66.69 62.63 69.52 192.168.0.1 : - - -The following is an output example using the '-e' option: \fb% fping -e a.b.com x.y.z.net 192.168.0.1
a.b.com is alive (18.9 ms) x.y.z.net is alive (9.51 ms) 192.168.0.1 is alive (0.35 ms)The following is an output example using the '-g' option: \fb% fping -g 192.168.0.1 192.168.0.6
192.168.0.0 is alive [<- 192.168.0.4] 192.168.0.4 is alive 192.168.0.1 is unreachable 192.168.0.2 is unreachable 192.168.0.3 is unreachable 192.168.0.5 is unreachable 192.168.0.6 is unreachableThe following is an output example using the '-s' option: \fb% fping -s a.b.com x.y.z.net 192.168.0.1
a.b.com is alive x.y.z.net is alive 192.168.0.1 is unreachable 3 targets 2 alive 1 unreachable 0 unknown addresses 4 timeouts (waiting for response) 6 ICMP Echos sent 2 ICMP Echo Replies received 0 other ICMP received 46.1 ms (min round trip time) 58.7 ms (avg round trip time) 71.3 ms (max round trip time) 4.153 sec (elapsed real time)AUTHORSRoland J. Schemers III, Stanford University, concept and versions 1.x RL "Bob" Morgan, Stanford University, versions 2.x ZeroHype Technologies Inc. (http://www.zerohype.com), versions 2.3x and up, fping website: http://www.fping.com .niDIAGNOSTICSExit status is 0 if all the hosts are reachable, 1 if some hosts were unreachable, 2 if any IP addresses were not found, 3 for invalid command line arguments, and 4 for a system call failure.BUGSHa! If we knew of any we would have fixed them!RESTRICTIONSSuccessful execution of this program requires that it be granted the net_icmpaccess privilege. .niSEE ALSOnetstat(1M), ping(1M), ifconfig(1M), rbac(5), privileges(5)