fping 命令详解

| 选择喜欢的代码风格  


fping 命令安装:

-bash/zsh: fping: command not found

apt-get install fping

apt-get install fping

apk add fping

#Arch Linux
pacman -S fping

#Kali Linux
apt-get install fping

dnf install fping
brew install fping

apt-get install fping

docker run cmd.cat/fping fping

#也可以到 fping 官网下载源码编译安装

wget https://fping.org/dist/fping-5.0.tar.gz
tar -xvf fping-5.0.tar.gz
cd fping-5.0/
make && make install

#您可以编译 fping 并支持 IPv6 地址,请按照以下步骤操作:
./configure --prefix=/usr/local --enable-ipv4 --enable-ipv6
make install

fping 命令补充说明:

fping 命令类似 ping,将 ICMP ECHO_REQUEST 数据包发送到网络主机。但比 ping 强大。与 ping 要等待某一主机连接超时或发回反馈信息不同,fping 给一个主机发送完数据包后,马上给下一个主机发送数据包,实现多主机同时 ping,fping 还可以在命令行中指定要 ping 的主机数量范围

fping 命令语法:

fping [ options ] [ systems... ]

fping 命令选项:

-a  # 显示存活的主机
-b  # ping 数据包的大小。(默认为56)
-c  # ping每个目标的次数 (默认为1)
-f  # 从文件获取目标列表(不能与 -g 同时使用)
-l  # 循环发送ping
-g  # 通过指定开始和结束地址来生成目标列表,可以使网段
-u  # 显示不可到达的目标

−4, −−ipv4
Restrict name resolution and IPs to IPv4 addresses.

−6, −−ipv6
Restrict name resolution and IPs to IPv6 addresses.

−a, −−alive
Show systems that are alive.

−A, −−addr
Display targets by address rather than DNS name. Combined with −d, the output will be both the ip and (if available) the hostname.

−b, −−size= BYTES
Number of bytes of ping data to send. The minimum size (normally 12) allows room for the data that fping needs to do its work (sequence number, timestamp). The reported received data size includes the IP header (normally 20 bytes) and ICMP header (8 bytes), so the minimum total size is 40 bytes. Default is 56, as in ping. Maximum is the theoretical maximum IP datagram size (64K), though most systems limit this to a smaller, system-dependent number.

−B, −−backoff=N
Backoff factor. In the default mode, fping sends several requests to a target before giving up, waiting longer for a reply on each successive request. This parameter is the value by which the wait time (−t) is multiplied on each successive request; it must be entered as a floating-point number (x.y). The default is 1.5.

−c, −−count=N
Number of request packets to send to each target. In this mode, a line is displayed for each received response (this can suppressed with −q or −Q). Also, statistics about responses for each target are displayed when all requests have been sent (or when interrupted).

−C, −−vcount=N
Similar to −c, but the per-target statistics are displayed in a format designed for automated response-time statistics gathering. For example:

 $ fping −C 5 −q somehost
 somehost : 91.7 37.0 29.2 − 36.8
shows the response time in milliseconds for each of the five requests, with the "−" indicating that no response was received to the fourth request.

−d, −−rdns
Use DNS to lookup address of return ping packet. This allows you to give fping a list of IP addresses as input and print hostnames in the output. This is similar to option −n/−−name, but will force a reverse-DNS lookup even if you give hostnames as target ( NAME− > IP− > NAME ).

−D, −−timestamp
Add Unix timestamps in front of output lines generated with in looping or counting modes (−l, −c, or −C).

−e, −−elapsed
Show elapsed (round-trip) time of packets.

−f, −−file
Read list of targets from a file. This option can only be used by the root user. Regular users should pipe in the file via stdin:

 $ fping < targets_file
−g, −−generate addr/mask

Generate a target list from a supplied IP netmask, or a starting and ending IP. Specify the netmask or start/end in the targets portion of the command line. If a network with netmask is given, the network and broadcast addresses will be excluded. ex. To ping the network, the specified command line could look like either:

 $ fping −g

 $ fping −g
−h, −−help

Print usage message.

−H, −−ttl=N

Set the IP TTL field (time to live hops).

−i, −−interval= MSEC
The minimum amount of time (in milliseconds) between sending a ping packet to any target (default is 10, minimum is 1).

−I, −−iface= IFACE
Set the interface (requires SO_BINDTODEVICE support).

−l, −−loop
Loop sending packets to each target indefinitely. Can be interrupted with Ctrl-C; statistics about responses for each target are then displayed.

−m, −−all
Send pings to each of a target host’s multiple IP addresses (use of option ’−A’ is recommended).

−M, −−dontfrag
Set the "Don’t Fragment" bit in the IP header (used to determine/test the MTU ).

−n, −−name
If targets are specified as IP addresses, do a reverse-DNS lookup on them to

−N, −−netdata
Format output for netdata (−l −Q are required). See: 

−o, −−outage
Calculate "outage time" based on the number of lost pings and the interval used (useful for network convergence tests).

−O, −−tos=N
Set the typ of service flag ( TOS ). N can be either decimal or hexadecimal (0xh) format.

−p, −−period= MSEC
In looping or counting modes (−l, −c, or −C), this parameter sets the time in milliseconds that fping waits between successive packets to an individual target. Default is 1000 and minimum is 10.

−q, −−quet
Quiet. Don’t show per-probe results, but only the final summary. Also don’t show ICMP error messages.

−Q, −−squiet= SECS
Like −q, but show summary results every n seconds.

−r, −−retry=N
Retry limit (default 3). This is the number of times an attempt at pinging a target will be made, not including the first try.

−R, −−random
Instead of using all-zeros as the packet data, generate random bytes. Use to defeat, e.g., link data compression.

−s, −−src
Print cumulative statistics upon exit.

−S, −−src=addr
Set source address.

−t, −−timeout= MSEC
Initial target timeout in milliseconds. In the default, non-loop mode, the default timeout is 500ms, and it represents the amount of time that fping waits for a response to its first request. Successive timeouts are multiplied by the backoff factor specified with −B.

In loop/count mode, the default timeout is automatically adjusted to match the "period" value (but not more than 2000ms). You can still adjust the timeout value with this option, if you wish to, but note that setting a value larger than "period" produces inconsistent results, because the timeout value can be respected only for the last ping.

Also note that any received replies that are larger than the timeout value, will be discarded.

−T n
Ignored (for compatibility with fping 2.4).

−u, −−unreach
Show targets that are unreachable.

−v, −−version
Print fping version information.

fping 命令实例

fping 选择性 ping 指定 IP

[root@CommandNotFound ~]$ fping 2>/dev/null is alive is alive is unreachable

fping 整个网段:

[root@CommandNotFound ~]
$ fping -g 2>/dev/null is alive is alive is unreachable is unreachable

... is unreachable is unreachable is unreachable is unreachable is unreachable is unreachable is unreachable

fping 整个网段,只显示存活的主机:

[root@CommandNotFound ~]
$fping -ag 2>/dev/null

fping 某一段 IP

[root@CommandNotFound ~]
$ fping -ag 2>/dev/null


fping 扩展阅读:

fping 命令评论