简介
fping是一个类似ping的程序,它使用互联网控制消息协议(ICMP)回显请求来确定目标主机是否正在响应。fping与ping的不同之处在于,您可以在命令行上指定任意数量的目标,或者指定一个包含要ping的目标列表的文件。fping将发送一个ping数据包,并以循环方式移动到下一个目标,而不是发送到一个目标直到它超时或回复。
官网
安装
# 例ubuntu
sudo apt install fping
# centos 7
sudo yum install fping
使用帮助
# fping -h
Usage: fping [options] [targets...]
Probing options:
-4, --ipv4 only ping IPv4 addresses
-6, --ipv6 only ping IPv6 addresses
-b, --size=BYTES amount of ping data to send, in bytes (default: 56)
-B, --backoff=N set exponential backoff factor to N (default: 1.5)
-c, --count=N count mode: send N pings to each target
-f, --file=FILE read list of targets from a file ( - means stdin)
-g, --generate generate target list (only if no -f specified)
(give start and end IP in the target list, or a CIDR address)
(ex. fping -g 192.168.1.0 192.168.1.255 or fping -g 192.168.1.0/24)
-H, --ttl=N set the IP TTL value (Time To Live hops)
-I, --iface=IFACE bind to a particular interface
-l, --loop loop mode: send pings forever
-m, --all use all IPs of provided hostnames (e.g. IPv4 and IPv6), use with -A
-M, --dontfrag set the Don't Fragment flag
-O, --tos=N set the type of service (tos) flag on the ICMP packets
-p, --period=MSEC interval between ping packets to one target (in ms)
(in loop and count modes, default: 1000 ms)
-r, --retry=N number of retries (default: 3)
-R, --random random packet data (to foil link data compression)
-S, --src=IP set source address
-t, --timeout=MSEC individual target initial timeout (default: 500 ms,
except with -l/-c/-C, where it's the -p period up to 2000 ms)
Output options:
-a, --alive show targets that are alive
-A, --addr show targets by address
-C, --vcount=N same as -c, report results in verbose format
-d, --rdns show targets by name (force reverse-DNS lookup)
-D, --timestamp print timestamp before each output line
-e, --elapsed show elapsed time on return packets
-i, --interval=MSEC interval between sending ping packets (default: 10 ms)
-n, --name show targets by name (reverse-DNS lookup for target IPs)
-N, --netdata output compatible for netdata (-l -Q are required)
-o, --outage show the accumulated outage time (lost packets * packet interval)
-q, --quiet quiet (don't show per-target/per-ping results)
-Q, --squiet=SECS same as -q, but add interval summary every SECS seconds
-s, --stats print final stats
-u, --unreach show targets that are unreachable
-v, --version show version
-x, --reachable=N shows if >=N hosts are reachable or not
使用示例
# 测试多个主机是否可达
# fping 8.8.8.8 www.google.com
8.8.8.8 is alive
www.google.com is alive
# 指定次数测试多个主机,显示延时等信息
# fping -c 3 8.8.8.8 www.google.com
8.8.8.8 : [0], 64 bytes, 1.52 ms (1.52 avg, 0% loss)
www.google.com : [0], 64 bytes, 1.79 ms (1.79 avg, 0% loss)
8.8.8.8 : [1], 64 bytes, 1.55 ms (1.54 avg, 0% loss)
www.google.com : [1], 64 bytes, 1.78 ms (1.78 avg, 0% loss)
8.8.8.8 : [2], 64 bytes, 1.54 ms (1.54 avg, 0% loss)
www.google.com : [2], 64 bytes, 1.74 ms (1.77 avg, 0% loss)
8.8.8.8 : xmt/rcv/%loss = 3/3/0%, min/avg/max = 1.52/1.54/1.55
www.google.com : xmt/rcv/%loss = 3/3/0%, min/avg/max = 1.74/1.77/1.79
# 从文件读取主机列表
# cat test.list
# dns
8.8.8.8
# google
www.google.com
# fping -c 3 -f test.list
8.8.8.8 : [0], 64 bytes, 1.52 ms (1.52 avg, 0% loss)
www.google.com : [0], 64 bytes, 1.84 ms (1.84 avg, 0% loss)
8.8.8.8 : [1], 64 bytes, 1.46 ms (1.49 avg, 0% loss)
www.google.com : [1], 64 bytes, 1.77 ms (1.81 avg, 0% loss)
8.8.8.8 : [2], 64 bytes, 1.48 ms (1.49 avg, 0% loss)
www.google.com : [2], 64 bytes, 1.76 ms (1.79 avg, 0% loss)
8.8.8.8 : xmt/rcv/%loss = 3/3/0%, min/avg/max = 1.46/1.49/1.52
www.google.com : xmt/rcv/%loss = 3/3/0%, min/avg/max = 1.76/1.79/1.84
种草
本文为"计算机网络实用工具系列"的内容之一,会持续更新其它相关博文
我的博文内容主要针对“计算机网络”、“安全”、“运维”和“云计算”方向,感兴趣朋友的请关注我,我将不定期发布新的博文并不断改进已发布博文。
后期依据大家对博文的评论,点赞及关注情况,针对大家感兴趣的内容我也会录制视频并整理出成套的学习资料免费分享给大家,期待能和大家一起交流学习。