The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tie::DNS - Tie interface to Net::DNS

VERSION

This document describes version 0.1 of Tie::DNS, released June 8, 2001

SYNOPSIS

use Tie::DNS;

tie(%dns, 'Tie::DNS');

print $dns{'foo.bar.com'}, "\n";

print $dns{'208.180.41.1'}, "\n";

DESCRIPTION

Net::DNS is a very complete, extensive and well-written module. It's also hard to use in many common cases. Tie::DNS is ment to make common DNS operations trivial, and more complex DNS operations easier.

EXAMPLES

Forward lookup

See Above.

Zone transfer

Get all of the A records from 'foo.com'. (Sorry foo.com if everyone hits your name server testing this module. :-)

tie (%dns, 'Tie::DNS', {'Domain' => 'foo.com'});

while (($name, $ip) = each %dns) { print "$name = $ip\n"; }

This obviously requires that your host has zone transfer privileges with a name server hosting that zone. The zone transfer is initiated with the first each, keys or values operation. The tie operation does a SOA query to find the name server for the cited zone.

Fetching multiple records

Pass the configuration parameter of 'multiple' to any Perl true value, and all FETCH values from Tie::DNS will be an array reference of records.

tie (%dns, 'Tie::DNS', {'multiple' => 'true'});

my $ip_ref = $dns{'cnn.com'}; foreach (@{$ip_ref}) { print "Address: $_\n"; }

Fetching records of type besides 'A'

Pass the configuration parameter of 'type' to one of the Net::DNS supported record types causes all FETCHes to get records of that type.

tie (%dns, 'Tie::DNS', { 'multiple' => 'true', 'type' => 'SOA'});

my $ip_ref = $dns{'cnn.com'}; foreach (@{$ip_ref}) { print "primary nameserver: $_\n"; }

Here are the most popular types supported:

CNAME - Returns the records canonical name. A - Returns the records address field. TXT - Returns the descriptive text. MX - Returns name of this mail exchange. NS - Returns the domain name of the nameserver. PTR - Returns the domain name associated with this record. SOA - Returns the domain name of the original or nameserver for this zone.

(The descriptions are right out of the Net::DNS POD.)

See Net::DNS documentation for further information about these types and a comprehensive list of all available types.

Fetching all of the fields associated with a given record type.

tie (%dns, 'Tie::DNS', {'type' => 'SOA'});

my $dns_ref = $dns{'cnn.com'}; foreach my $field (keys %{$dns_ref}) { print "$field = " . ${$dns_ref}{$field} . "\n"; }

This code fragment will print all of the SOA fields associated with cnn.com.

Changing various arguments to the tie on the fly

tie (%dns, 'Tie::DNS', {'type' => 'SOA'}); print $dns{'cnn.com'} . "\n";

tied(%dns)->args({'type' => 'A'}); print $dns{'cnn.com'} . "\n";

This code fragment first does an SOA query for cnn.com, and then changes the default mode to A queries, and displays that.

Simple Dynamic Updates

Assign into the hash, key DNS name, value IP address, to add a record to the zone in the domain argument. For instance:

tie (%dns, 'Tie::DNS', { 'domain' => 'realms.lan', 'multiple' => 'true'});

$dns{'food.realms.lan.'} = '131.22.40.1';

foreach (@{$dns{'food'}}) { print " $_\n"; }

TODO

This .4 release supports the basic functionality of Net::DNS. The 1.0 release will support the following:

Very likely some application level caching options.

Different access methods for forward and reverse lookups.

The 2.0 release will strive to support DNS security options.

AUTHOR

Dana M. Diederich <dana@realms.org>

BUGS

This project is very incomplete. in-addr.arpa zone transfers aren't yet supported. This module ONLY supports named arguments, not positional.

Patches, flames, opinions, enhancement ideas are all welcome.

COPYRIGHT

Copyright (c) 2001, Dana M. Diederich. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License (see http://www.perl.com/perl/misc/Artistic.html)