head 1.2; access; symbols; locks; strict; comment @# @; 1.2 date 2003.04.25.22.04.04; author wessels; state Exp; branches; next 1.1; 1.1 date 2003.04.25.21.51.35; author wessels; state Exp; branches; next ; desc @@ 1.2 log @*** empty log message *** @ text @#!/usr/bin/perl # $Id$ # # perl code to send traceroute requests to a bunch of 'traceroute servers' on remote # hosts. The traceroute servers are running 'udp-tracerouted' from inted. This # script collects the replies, formats them, and presents a table sorted by RTT. # # @@sources array holds address and port of traceroute servers. # # warning, this code written by beginner perl programmer long ago! $|=1; require 'sys/socket.ph'; $sockaddr = 'S n a4 x8'; ($name, $aliases, $proto) = getprotobyname("udp"); $thissock = pack($sockaddr, &AF_INET, 0, "\0\0\0\0"); die "socket: $!\n" unless socket (SOCK, &AF_INET, &SOCK_DGRAM, $proto); @@sources = ( 'host1:8989', 'host2:8989', 'host3:8989'); # may want to hard-code some FQDNs as special cases # $FQDN{'192.168.0.1'}='host1.example.com'; %rqpairs = &get_request; unless (defined $rqpairs{'dest'}) { print "ERROR: no dest parameter\n"; exit 0; } $dest = $rqpairs{'dest'}; while ((shift @@sources) =~ /([^:]+):(\d+)/) { $host = $1; $port = $2; ($fqdn, $aliases, $type, $len, $themaddr) = gethostbyname($host); $ADDR{$host} = pack('Sna4x8', &AF_INET, $port, $themaddr); $ip = join('.', unpack('C4', $themaddr)); $FQDN{$ip} = $fqdn unless defined ($FQDN{$ip}); } $len = length($dest); $n = 0; foreach $host (keys %ADDR) { $port = $PORT{$host}; @@ip = split('\.', $IP{$host}); $them = pack('SnC4x8', &AF_INET, $port, @@ip); ($sport,@@IP) = unpack('x2nC4x8', $ADDR{$host}); die "send: $!\n" unless send(SOCK, $dest, 0, $ADDR{$host}); $n++; } print "Content-Type: text/html\r\n"; print "\r\n"; print "
Summary table is printed at the end.
\n"; $timeleft = 60.0; while ($n > 0 && $timeleft >= 0.0) { $rin = ''; vec($rin,fileno(SOCK),1) = 1; ($nfound,$timeleft) = select($rout=$rin, undef, undef, $timeleft); last if ($nfound == 0); die "recv: $!\n" unless $theiraddr = recv(SOCK, $reply, 8192, 0); ($junk, $junk, $sourceaddr, $junk) = unpack($sockaddr, $theiraddr); $ip = join('.', unpack('C4', $sourceaddr)); $reply =~ s/\d+\s+\*\s+\*\s+\*// while ($reply =~ /\d+\s+\*\s+\*\s+\*/); $reply =~ s/\d+\s+\*\s+\*// while ($reply =~ /\d+\s+\*\s+\*/); $reply =~ s/\d+\s+\*// while ($reply =~ /\d+\s+\*/); $REPLY{$ip} = $reply; printReply($ip,$reply); $n--; } foreach $ip (keys %REPLY) { $HOPS{$ip} = &hops($REPLY{$ip}); $RTT{$ip} = &rtt($REPLY{$ip}); } print "Summary of results, sorted by RTT:\n"; print "
\n"; print "
| Cache | \n"; print "RTT | \n"; print "HOPS | \n"; print "
|---|---|---|
| $FQDN{$ip} | \n"; printf "%.3f | \n", $RTT{$ip}; printf "%d | \n", $HOPS{$ip}; print "
\n";
print "$reply
\n";
print "