IPアドレスリストをpingして重複項目を出力します。

IPアドレスリストをpingして重複項目を出力します。

LinuxでIPアドレスリスト(テキストファイル)をpingし、重複した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アドレスのリストが含まれています。

おすすめ記事