Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement