DevTech101

DevTech101

Use the perl script below to check your DNS performance.

Make sure to replace the search string and your DNS provider IP address.

#!/usr/bin/perl
 
@ns     = @ARGV;
push(@ns,'8.8.8.8', '4.2.2.1') unless @ns;
$domain = "www.devtech101.com"; 

use Net::DNS;
use Time::HiRes;  # high resolution timing required
use Time::Stopwatch;
use Number::Format qw(:subs);
use Statistics::Descriptive;
 
 
tie my $time, 'Time::Stopwatch';  # code timer
 
$res   = Net::DNS::Resolver->new;
 
foreach $ns (@ns) {
    $res->nameservers($ns);
    print '='x75,"\n";
 
    my $stat = Statistics::Descriptive::Sparse->new();
    print "Using nameserver: $ns\n\n";
    my $loop    = 0;
    while ($loop < 50) {
        $loop ++;
        print "$loop.\t";
        my $diff = 0;
        $time = 0;
        my $query = $res->search($domain);
        $diff += $time;
        $time = 0;
        $diff -= $time;
        $stat->add_data($diff);
        $diff   = round($diff,3);
        print "$diff\t";
        if ($query) {
            foreach my $rr ($query->answer) {
                next unless $rr->type eq "A";
                print $rr->address, "\n";
            }
        } else {
            print "query failed: ", $res->errorstring, "\n";
        }
    }
    print("count: ", $stat->count(), " iterations\n",
              "mean:  ", $stat->mean(), " seconds\n",
                        "s.d.:  ", $stat->standard_deviation(), " seconds\n");
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
%d bloggers like this: