Announcing Net::RNDC - Communicate with BIND through Perl
I often have need to communicate with ISC's BIND programattically and I haven't found any libraries out there to do that.
Often, what you'll see is a wrapper around BIND's rndc utility that forks, execs, passes it arguments, and then parses the output.
This is okay if you're on a box that can fork and has rndc installed, but that's not a safe assumption.
So I spent some time digging through BIND source and deconstructing the RNDC protocol (which was actually quite fun) and came up with Net::RNDC:
use Net::RNDC;
my $rndc = Net::RNDC->new(
host => '127.0.0.1',
port => 953, # Defaults to 953
key => 'abcd',
);
if (!$rndc->do('status')) {
die "RNDC failed: " . $rndc->error;
}
print $rndc->response;
The base Net::RNDC interface is synchronous, but you can use Net::RNDC::Session asynchronously, or just use Net::RNDC::Packet itself to generate/parse RNDC packets.
The packet interface isn't yet well defined (just read/write entries in a hashref), but I hope to improve on that soon.
Enjoy,
-- Matthew Horsfall (alh)
PS: Thanks to my employer Dyn for allowing us 2 days a month to hack on projects that we want!
Leave a comment