ping 与 fping
ping
简介
info ping
可得:
'ping' uses ICMP datagrams to provoke a response from the chosen destination host, mainly intending to probe whether it is alive.
The used datagram, of type 'ECHO_REQUEST', contains some header information and some additional payload, usually a timestamp. By a suitable choice of payload, different host or router properties are detectable, as the emitted datagram travels to its destination.
命令
通过 ping --help
我学到几个有用的选项:
ping [options] <destination>
<destination>
dns name or ip address-c <count>
stop after<count>
replies-i <interval>
seconds between sending each packet-w <deadline>
reply wait<deadline>
in seconds-f <deadline>
flood ping
fping
简介
man ping
可得:
fping is a program like ping which uses the Internet Control Message Protocol (ICMP) echo request to determine if a target host is responding.
fping differs from ping in that you can specify any number of targets on the command line, or specify a file containing the lists of targets to ping. Instead of sending to one target until it times out or replies, fping will send out a ping packet and move on to the next target in a round-robin fashion.
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.
命令
通过 man ping
我学到几个有用的选项:
-a, --alive
Show systems that are alive.-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 192.168.1.0/24, the specified command line could look like either:fping -g 192.168.1.0/24
orfping -g 192.168.1.1 192.168.1.254
-s, --src
Print cumulative statistics upon exit.
练习(我的内网 IP 为 192.168.43.79
):
1 | fping -s 192.168.43.76 192.168.43.79 |
shell 上显示四部分:
存活主机
192.168.43.79 is alive
;ICMP 差错报文, 标准错误输出信息,可以用
2>/dev/null
去除;每个地址最多询问 四次
不可达主机:
192.168.43.76 is unreachable
-a
选项便是去除这一部分累计数据
-s
选项的作用便是在退出前,输出累计统计数据。
-g
选项,根据起、始 IP 生成列表,遍历。
1 | fping -g 192.168.43.76 192.168.43.79 2>/dev/null |
常用:fping -ag IP 或起始IP 2>/dev/null