#!/usr/bin/perl # Asgard Labs, 2004 (C) thorolf # small tool to map network connections # mtr, graphviz is needed use GraphViz; if ($ARGV[0]) { @dest = @ARGV; } else { @dest = ("www.dod.mil"); } my $g = GraphViz->new(directed => 1,layout => 'dot'); my $last = "localhost"; foreach $tt (@dest) { open(IN,"mtr -t -n -c 5 -r $tt |") or die ("can't start mtr\n"); while($line = ) { chomp($line); if ($line =~ /^\s+\d+\./) { ($ip,$gate,$lost,$r,$s,$m,$a,$mx) = ($line =~ /^\s+\d+\.\s+(.+)\s*(\d+\.\d+)%\s*(\d*)\s*(\d*)\s*(\d{1,}\.\d{1,2})\s*(\d{1,}\.\d{1,2})\s*(\d{1,}\.\d{1,2}).*$/); $ip =~ s/ //g; if ($line =~ /\?\?\?/) {next;} $color = "black"; if ((int($a) > 20) && (int($a) <50)) {$color = "green";} elsif ((int($a) >50) && (int($a) <100)) {$color= "blue";} elsif (int($a) >100) {$color="red";} #$g->add_edge("$last" => "$ip",color => "$color", label=> "$a ms");\n"; $g->add_edge("$last" => "$ip"); $last="$ip"; } } close(IN); $g->add_edge("$last"=>"$tt"); $last="localhost"; } open (X, "> snap.png"); print X $g->as_png; close(X);