Small Mosaic


Categories:

/books
/career
/codinghorrors
/events
/geekstuff
/justdont
/languages
/languages/bash
/linkshot
/magazines
/meta
/misctech
/movies
/nottech
/operatingsystems
/operatingsystems/linux
/operatingsystems/linux/debian
/operatingsystems/solaris
/perl
/presentations
/programming
/python
/ruby
/security
/security/apache
/security/tools
/serversmells
/services
/services/dns
/sites
/specifications
/sysadmin
/testing
/tools
/tools/commandline
/tools/firefox
/tools/gui
/tools/network
/tools/online
/tools/online/greasemonkey
/tools/puppet
/unixdaemon

Archives:

July 20101
June 20104
May 20102
April 20101
March 20108
February 20101
January 20102
October 20092
September 200910
August 200910
July 20094
June 20091
April 20093
March 20097
February 20094
January 200917
Full Archives

Wed, 07 Jan 2009

Which Zones Have a Specified Subdomain? - DNS Delvings (1)
It's been another day of many DNS changes and while the work itself has been amazingly dull, life draining, scut work at least one positive thing's come out of it - my appreciation for the Net::DNS perl module has grown.

While it's possible to do nearly anything DNS query related with the dig command it's a lot easier to extract the data and reuse certain fields if you have access to a decent data structure rather than grepping bits of text out. Over the next couple of days, while I'm elbow deep in our domain name system, I'll be posting, hopefully useful, little snippets of code to illustrate how you can get a lot of value from little code.

Today we have a script that accepts checks for the presence of the specified subdomain in all the domains mentioned on the command line and reports success or failure. I've not had to run it in anger yet but it should, fingers crossed, save me a lot of digging around tomorrow. You invoke the script like this - check-subdomains-presence blog example.org example.com.


#!/usr/bin/perl -w
use strict;
use warnings;
use Net::DNS;

die "$0: please supply a subdomain to look for and one or more zones to look in\n"
  unless @ARGV >= 2;

my $domain = shift;
my @zones  = @ARGV;

my $res   = Net::DNS::Resolver->new;

for my $zone ( @zones ) {
  my $query = $res->query( "$domain.$zone", "A");

  if ($query) {
    foreach my $rr (grep { $_->type eq 'A' } $query->answer) {
      print "Present - $domain.$zone\n";
    }
  } else {
    warn "Absent - $domain.$zone - ", $res->errorstring, "\n";
  }
}

The code is short, easy to read through and will hopefully whet your appetite for the longer posts to come...`

Like this post? - Digg Me! | Add to del.icio.us! | reddit this!

Posted: 2009/01/07 23:11 | /services/dns | Permanent link to this entry | This entry and same date


books career codinghorrors events geekstuff justdont magazines meta misctech movies nottech operatingsystems/linux operatingsystems/linux/debian operatingsystems/solaris perl presentations programming python ruby security security/apache security/tools serversmells services/dns sites sysadmin testing tools/commandline tools/firefox tools/gui tools/network tools/online tools/online/greasemonkey tools/puppet unixdaemon

Copyright © 2000-2010 Dean Wilson XML feed logo