#!/usr/bin/perl open(FILE, "/usr/sbin/traceroute -n $ARGV[0] 2>/dev/null|"); while () { $data = $_; if ($data =~ m/^\s?\d+\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([0-9.]* ms|\*)\s+([0-9.]* ms|\*)\s+([0-9.]* ms|\*)/) { $ip = $1; $a = $2; $b = $3; $c = $4; $a =~ s/ ms//; $b =~ s/ ms//; $c =~ s/ ms//; $total = 0; $counter = 0; if ($a ne "*") { $total = $total + $a; $counter++; } if ($b ne "*") { $total = $total + $b; $counter++; } if ($c ne "*") { $total = $total + $c; $counter++; } $total = $total / $counter; print "$ip: \t"; printf("%7.3f", $total); print " ms\n"; } } close(FILE);