Last Updated: February 25, 2016
·
1.358K
· franklouwers

mtr/traceroute to a url

I often want to traceroute (or better: mtr) to a host for debugging or curiosity purposes.

I also noticed that while Safari doesn't show you the http:// or https:// prefix, it does add the prefix when copy pasting.

So I often find myself trying to mtr http://coderwall.com/p/new which doesn't work.

If you add the following function to your .zshrc (or adapt it to match your shell-of-choice), it uses Ruby to extract the hostname and feeds that mtr.

 function mtr {
     host=`ruby -ruri -e "puts (URI.parse('$1').host or '$1')"`
     echo host: $host
     /usr/local/sbin/mtr -t $host
}