Thursday 27 January 2011

hop counter

I was playing with traceroute and felt like "rolling my own" hop counter, so this is what I put together in a few seconds:

for ((i=1;i<21;i++)); do echo -n .; if ping -c 1 -t $i somehost.com >/dev/null 2>&1; then break; fi; done; echo " $i hops"

You'll reasonably quickly see a few dots (especially if the router in question doesn't respond to pings) and a final count.  You can of course tweak the options to ping to make it more like traceroute (max wait time, max hops, etc).  The output is something like:

.......... 10 hops

Now, for some reason `traceroute` needs superuser access for the ICMP option, and yet you can do the same with ping.

No comments:

 
Copyright 2009 Another Blog. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan