Listing06_Configure_All_NS_In_Zone (Perl)

This code can be found in Chapter 8 of Managing Enterprise Active Directory Services

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# From the book "Managing Enterprise Active Directory Services"
# ISBN: 0-672-32125-4

use strict;
use Net::DNS;
use DnsCmd;

my $domain = 'xyz.com';

my %DNS_Settings = ( 
  NoRecursion      => 0,
  LocalNetPriority => 1,
  RoundRobin       => 1,
  LooseWildCarding => 1,
  LogFileMaxSize   => 1024,
  StrictFileParsing => 1,
  ScavengingInterval => 12,
  MaxCacheTtl       => 60,
);

my $res = Net::DNS::Resolver->new();
my $query = $res->search("$domain", "NS");
if ($query) {
   foreach my $rr ($query->answer) {
      next unless $rr->type eq "NS";
      print "Configuring ",$rr->nsdname,"\n";
      my $dnscmd = DnsCmd->new($rr->nsdname);
      foreach my $prop (sort keys %DNS_Settings) {
         $dnscmd->Config($prop => $DNS_Settings{$prop});
         if ($dnscmd->error) {
            print "ERROR occurred: ",$dnscmd->output;
         }
      }
   }
}
else {
   die "NS query failed: ", $res->errorstring, "\n";
}

This code has been viewed 645 times.

New from the creators of TechTasks.com: StatSheet.com