|
I wanted to compare the overall latency and hop count of 2 ISP's. This is the script I wrote for that.
Usage: ./network-test.pl listofips.txt
listofips.txt was a list gathered from the access_log of a web site hosted here
#!/usr/bin/perl
use Net::Ping;
$inputfile=$ARGV[0];
$|=1;
open (IP, "$inputfile") || die "Cannot open list of IP's";
$totalpings=0;
$pingavgs=0.0;
$totaltrace=0;
$hopsavg=0;
while () {
chomp;
$ip=$_;
print $ip,"\t";
$p = Net::Ping->new("icmp");
# test to make sure the host is up before we continue testing
if ($p->ping($ip,2)) {
$totalpings++;
# use ping to get the average round trip time for 10 packets
$pingavg=`ping -n -c 10 -q $ip 2>/dev/null | awk -F/ '/avg/ {print \$5}'`;
chomp $pingavg;
print $pingavg,"\t";
$pingavgs+=$pingavg;
# use traceroute to get the number of network hops
$hops=`traceroute -n $ip 2>/dev/null | wc -l`;
chomp $hops;
if ($hops < 30) {
print $hops;
$hopsavg+=$hops;
$totaltrace++;
} else {
print "too many hops";
}
} else {
print "host unreachable";
}
print "\n";
}
close IP;
print "===================================\n";
print "Total pings: ", $totalpings ,"\n";
print "Average Latency: ", $pingavgs/$totalpings ,"\n";
print "Total traces: ", $totaltrace ,"\n";
print "Average Hops: ", $hopsavg/$totaltrace ,"\n";
Last modified: Wednesday, December 31 1969 @ 19:00 EST
© Ian Samuel, 2012
http://braindump.MrZesty.net
|