<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Matthew Horsfall</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/matthew_horsfall/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/matthew_horsfall/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/matthew_horsfall//707</id>
    <updated>2013-01-04T17:01:35Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Announcing Net::RNDC - Communicate with BIND through Perl</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/matthew_horsfall/2013/01/announcing-netrndc---communicate-with-bind-through-perl.html" />
    <id>tag:blogs.perl.org,2013:/users/matthew_horsfall//707.4176</id>

    <published>2013-01-04T16:49:46Z</published>
    <updated>2013-01-04T17:01:35Z</updated>

    <summary>I often have need to communicate with ISC&apos;s BIND programattically and I haven&apos;t found any libraries out there to do that. Often, what you&apos;ll see is a wrapper around BIND&apos;s rndc utility that forks, execs, passes it arguments, and then...</summary>
    <author>
        <name>Matthew Horsfall (alh)</name>
        
    </author>
    
        <category term="Add category" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/matthew_horsfall/">
        <![CDATA[<p>I often have need to communicate with ISC's <a href="https://www.isc.org/software/bind">BIND</a> programattically and I haven't found any libraries out there to do that.</p>

<p>Often, what you'll see is a wrapper around BIND's rndc utility that forks, execs, passes it arguments, and then parses the output.</p>

<p>This is okay if you're on a box that can fork and has rndc installed, but that's not a safe assumption.</p>

<p>So I spent some time digging through BIND source and deconstructing the RNDC protocol (which was actually quite fun) and came up with <a href="https://metacpan.org/module/WOLFSAGE/Net-RNDC-0.002/lib/Net/RNDC.pm">Net::RNDC</a>:<br />
<blockquote><pre><br />
use Net::RNDC;<br />
 <br />
my $rndc = Net::RNDC->new(<br />
  host => '127.0.0.1',<br />
  port => 953,         # Defaults to 953<br />
  key  => 'abcd',<br />
);<br />
 <br />
if (!$rndc->do('status')) {<br />
  die "RNDC failed: " . $rndc->error;<br />
}<br />
 <br />
print $rndc->response;<br />
</pre></blockquote></p>

<p>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.</p>

<p>The packet interface isn't yet well defined (just read/write entries in a hashref), but I hope to improve on that soon.</p>

<p>Enjoy,</p>

<p>-- Matthew Horsfall (alh)</p>

<p>PS: Thanks to my employer <a href="http://dyn.com">Dyn</a> for allowing us 2 days a month to hack on projects that we want!</p>]]>
        
    </content>
</entry>

</feed>
