0

In Linux how can I ping a list of IP addresses (in a text file) and only output those that have duplicate ping replies?

  • 6
    what do you mean by " duplicate ping replies" ? – Rahul Patil Jul 7 '13 at 17:51
  • I guess duplicate replies are described in the man page: "ping will report duplicate and damaged packets. 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." – rush Jul 7 '13 at 18:36
4

If you're talking about duplicates described in the man page:

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.

It will produce output like this:

$ 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!)

So you have just to iterate over the list in cycle:

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

Where ip_list.txt contains new line separated ip addresses list.

  • thanks you for the fast reply . but have you ever noticed that sometimes you can ping an ip address using an online ping tool and it gives you a reply but when you use the linux terminal it doesn't give you a ping reply. what could be the problem ? find it very strange. or could it be my isp blocking the duplicate ping relies ? – Eric Jul 7 '13 at 18:56
  • my ping does not understand -c : ping -c4 gives error message Incorrect option -c4. along with the usage text. I have an option -n count to ask for count echos. Does your -c4 mean -n 4? (In case others have the same ping as I...) – Max Nov 9 '18 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.