Skip to content

Instantly share code, notes, and snippets.

@simonmcc
Created June 26, 2016 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonmcc/2ef0ccf92d7844a8931e41ab9c6940ae to your computer and use it in GitHub Desktop.
Save simonmcc/2ef0ccf92d7844a8931e41ab9c6940ae to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Net::DNS;
use DBI;
my $samplesize = 100;
my %results = ();
$results{'cambridge'} = 0;
$results{'internap'} = 0;
$results{'paetec'} = 0;
$results{'total_hits'} = 0;
my %sites = (
'66.155.171.116' => 'paetec',
'69.25.47.116' => 'internap',
'64.69.12.116' => 'cambridge'
);
my $res = Net::DNS::Resolver->new(
nameservers => [qw(127.0.0.1)],
recurse => 0,
# debug => 1,
);
for(my $i=1; $i <= $samplesize; $i++)
{
my $query = $res->search("as00.estara.com");
my $j = 1;
foreach my $rr ($query->answer)
{
# Skip over anything but A records
next unless $rr->type eq "A";
# Record the results
# interested in how many returned & which DC
print "Sample $i: address:" . $rr->address . ", site:" . $sites{$rr->address} . "\n";
$results{$sites{$rr->address}}++;
$results{'total_hits'}++;
# $results{$sites{$rr->address}.'-pos-'.$j}++;
}
# Reset the position counter
$j = 1;
# cache-ttl is 20s, so wait until so that we get fresh data
sleep 2;
}
print "\n\n#### WRR DNS Results\n";
while (my ($site, $hits) = each(%results))
{
my $pcent = ($hits/$results{'total_hits'})*100;
my $pcent2 = ($hits/$samplesize)*100;
print "$site: $hits, $pcent2% (sample size), $pcent% (total RR)\n";
}
my $dsn = "DBI:mysql:database=local;host=localhost;";
my $dbh = DBI->connect($dsn, 'root', '');
my $sth = $dbh->prepare("select content, prio from records where name='as00.estara.com'");
$sth->execute;
print "\n\nDesired priorities were:\n";
while (my $ref = $sth->fetchrow_hashref())
{
# Desired priorities were..
print $sites{$ref->{'content'}} .' '. $ref->{'prio'}."/10, " . (10-$ref->{'prio'})*10 ."% \n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment