Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/rc/tracenet

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

# collect topology of network by doing a traceroute of 
# every host this can get very slow if many hosts timeout.
fn dotrace {
	cat $* |
	while(s=`{read}){
	    ip/traceroute $s | 
		awk -v 'prev='^$sysname '
			$1 ~ "^[0-9]+.[0-9]+.[0-9]+.[0-9]+$" {
				host = $5
				if(host == "")
					host = $1;
				printf("%s %s %s\n", $2, prev, host);
				prev = host;
			}
		'
	}
}

# Draw network topology using dot. We exclude leaf nodes as there are
# probably many of these. Each vertex is labeled with the RTT in milliseconds.
fn dograph {
	@{
	echo 'graph tracenet {' 
	sort +1 $* | 
		uniq +1 |
		awk '{
			rtt = $1
			src = $2
			dst = $3
			map[src "|" dst] = rtt;
			num[src "|" dst]++;
			hits[src]++;
			hits[dst]++;
		}
		END{
			for(pair in map){
				rtt = map[pair];
				n = split(pair, a, "|");
				src = a[1];
				dst = a[2];
				if(hits[dst] > 1)
					printf("\t \"%s\" -- \"%s\" [label=%5.1f]\n",
						src, dst, rtt/1000);
			}
		}
	'
	
	echo '}'
	} |
		dot '-Gsize=11,8' '-Grotate=90' -Tps 
}

fn usage {
	echo 'usage: tracenet -t [ip-list] > tracenet.out       # trace network' >[1=2]
	echo 'or     tracenet -g [tracenet.out] > tracenet.ps   # draw graph' >[1=2]
	exit 'usage'
}

prog=usage
while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
	switch($1){
	case -t
		prog=dotrace
		shift
	case -g
		prog=dograph
		shift
	case -*
		usage
	}
}

if(! ~ $#* 0 && ~ $1 --)
	shift

$prog $*


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].