#!/bin/sh # Copyright © 1999, 2000 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. args=$@ 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 ) } if [ "$_XMTR" = 1 ]; then # If $_XMTR is set, then we're already running in our xterm window # (this script is recursive.) # If no host name was specified, prompt for one. if [ $# = 0 ]; then echo -n "Host: " read h args="$h" else h="$1" fi name="$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 -t -u -n | tail +3 | sed 's/ */ /g' | cut -d' ' -f5 | sed 's/:.*//' | 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 name="$h" # take off the commentary IP address, if any h=`echo $h | sed 's/ (.*)$//'` args="$h" fi # set xterm's window and icon title. echo "]0;mtr $name" clear # now actually do the traceroute. mtr $args || (sleep 3; exit 1) else # This is our outer invocation -- just launch an appropriately sized/colored # xterm, re-executing this very script (to get into the first clause of the # "if" above.) # cmd="mtr $args" title="$cmd" export _XMTR=1 exec xterm +sb -geom =80x40 -fg yellow -bg black -T mtr -e $argv0 $@ fi