Ping IP 地址列表并输出重复项

Ping IP 地址列表并输出重复项

在 Linux 中,如何 ping IP 地址列表(在文本文件中)并仅输出那些具有重复 ping 回复的地址?

答案1

如果您正在谈论手册页中描述的重复项:

Duplicate packets should never occur, and seem to be caused by 
inappropriate link-level retransmissions. Duplicates may occur 
in many situations and are rarely (if ever) a good sign, although 
the presence of low levels of duplicates may not always be cause 
for alarm.

它将产生如下输出:

$ ping -n 192.x.y.z
PING x.com (192.x.y.z) 56(84) bytes of data.
64 bytes from 192.x.y.z: icmp_req=1 ttl=120 time=51.8 ms
64 bytes from 192.x.y.z: icmp_req=1 ttl=120 time=51.8 ms (DUP!)
64 bytes from 192.x.y.z: icmp_req=1 ttl=120 time=52.3 ms (DUP!)

所以你只需循环遍历列表:

while read ip ; do ping -c4 $ip | grep -q 'DUP!' && echo "$ip duplicates" ; done < ip_list.txt

其中 ip_list.txt 包含新行分隔的 IP 地址列表。

相关内容