#!/bin/sh # Copyright © 1999-2008 Jamie Zawinski # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that # the above copyright notice appear in all copies and that both that # copyright notice and this permission notice appear in supporting # documentation. No representations are made about the suitability of this # software for any purpose. It is provided "as is" without express or # implied warranty. # # Created: 5-Nov-99. # # Launches a Terminal window running mtr. You can drag this .command file # to your OSX dock as a shortcut to launch mtr and prompt for a host name. # Hitting RET at the prompt gives you a list of hosts to which you have # active network connections. PATH=/opt/local/sbin:$PATH export PATH argv0="$0" # we have to use "netstat -n" and then resolve the names ourselves, # because netstat unconditionally truncates names at 18 characters!! # resolve() { ( IFS=' ' for h in $* ; do hh=`host $h 2>/dev/null | sed -n 's/^.* domain name pointer //p'` if [ -z "$hh" ]; then echo "$h" else echo "$hh ($h)" fi done ) } # prompt for host name clear /bin/echo -n "MTR to host (RET for list): " read h # If the host name was '', then list active network connections, and # let the user choose from the list (or type another host name.) # if [ -z "$h" ]; then hosts=`netstat -n -f inet | tail +3 | sed 's/ */ /g' | cut -d' ' -f5 | sed 's/:.*//' | sed -n 's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/p' | sort | uniq` echo '' echo 'Active connections:' echo '' PS3="Selection or host name: " # have to split only on lines, not on whitespace oIFS="$IFS" IFS=' ' hosts=`resolve $hosts` select h in $hosts; do break done IFS="$oIFS" # if the user types a non-number return, then "select" sets $REPLY to it. if [ -z "$h" ]; then h="$REPLY" fi # take off the commentary IP address, if any h=`echo $h | sed 's/ (.*)$//'` fi # set window title osascript <