use Net::DNS;
The programmer should be familiar with the structure of a DNS packet. See RFC 1035 or DNS and BIND (Albitz & Liu) for details.
Do not assume that RR objects will be of the type requested. The type of an RR object must be checked before calling any methods.
use Net::DNS; print Net::DNS->version, "\n";
Returns the version of Net::DNS.
# Use a default resolver -- can not get an error string this way. use Net::DNS; my @rr = rr("example.com"); my @rr = rr("example.com", "AAAA"); my @rr = rr("example.com", "AAAA", "IN"); # Use your own resolver object. my $res = Net::DNS::Resolver->new; my @rr = rr($res, "example.com" ... ); my ($ptr) = rr("2001:DB8::dead:beef");
The "rr()" method provides simple RR lookup for scenarios where the full flexibility of Net::DNS is not required.
Returns a list of Net::DNS::RR objects for the specified name or an empty list if the query failed or no record was found.
See ``EXAMPLES'' for more complete examples.
# Use a default resolver -- can not get an error string this way. use Net::DNS; my @mx = mx("example.com"); # Use your own resolver object. my $res = Net::DNS::Resolver->new; my @mx = mx($res, "example.com");
Returns a list of Net::DNS::RR::MX objects representing the MX records for the specified name. The list will be sorted by preference. Returns an empty list if the query failed or no MX record was found.
This method does not look up address records; it resolves MX only.
$update = Net::DNS::Update->new( 'example.com' ); $update->push( prereq => nxrrset('example.com. AAAA') ); $update->push( update => rr_add('example.com. 86400 AAAA 2001::DB8::F00') );
# RRset exists (value-independent) $update->push( pre => yxrrset("host.example.com AAAA") );
Meaning: At least one RR with the specified name and type must exist.
# RRset exists (value-dependent) $update->push( pre => yxrrset("host.example.com AAAA 2001:DB8::1") );
Meaning: At least one RR with the specified name and type must exist and must have matching data.
Returns a Net::DNS::RR object or "undef" if the object could not be created.
$update->push( pre => nxrrset("host.example.com AAAA") );
Meaning: No RRs with the specified name and type can exist.
Returns a Net::DNS::RR object or "undef" if the object could not be created.
$update->push( pre => yxdomain("host.example.com") );
Meaning: At least one RR with the specified name must exist.
Returns a Net::DNS::RR object or "undef" if the object could not be created.
$update->push( pre => nxdomain("host.example.com") );
Meaning: No RR with the specified name can exist.
Returns a Net::DNS::RR object or "undef" if the object could not be created.
$update->push( update => rr_add("host.example.com AAAA 2001:DB8::c001:a1e") );
Meaning: Add this RR to the zone.
RR objects created by this method should be added to the ``update'' section of a dynamic update packet. The TTL defaults to 86400 seconds (24 hours) if not specified.
Returns a Net::DNS::RR object or "undef" if the object could not be created.
# Delete all RRsets. $update->push( update => rr_del("host.example.com") );
Meaning: Delete all RRs having the specified name.
# Delete an RRset. $update->push( update => rr_del("host.example.com AAAA") );
Meaning: Delete all RRs having the specified name and type.
# Delete a specific RR. $update->push( update => rr_del("host.example.com AAAA 2001:DB8::dead:beef") );
Meaning: Delete the RR which matches the specified argument.
RR objects created by this method should be added to the ``update'' section of a dynamic update packet.
Returns a Net::DNS::RR object or "undef" if the object could not be created.
$soa->serial(SEQUENTIAL); $soa->serial(YYYMMDDxx);
$successor = $soa->serial( SEQUENTIAL );
The existing serial number is incremented modulo 2**32.
$successor = $soa->serial( UNIXTIME );
The Unix time scale will be used as the basis for zone serial numbering. The serial number will be incremented if the time elapsed since the previous update is less than one second.
$successor = $soa->serial( YYYYMMDDxx );
The 32 bit value returned by the auxilliary "YYYYMMDDxx()" function will be used as the base for the date-coded zone serial number. Serial number increments must be limited to 100 per day for the date information to remain useful.
use Net::DNS; my @sorted = rrsort( $rrtype, $attribute, @rr_array );
"rrsort()" selects all RRs from the input array that are of the type defined by the first argument. Those RRs are sorted based on the attribute that is specified as second argument.
There are a number of RRs for which the sorting function is defined in the code.
For instance:
my @prioritysorted = rrsort( "SRV", "priority", @rr_array );
returns the SRV records sorted from lowest to highest priority and for equal priorities from highest to lowest weight.
If the function does not exist then a numerical sort on the attribute value is performed.
my @portsorted = rrsort( "SRV", "port", @rr_array );
If the attribute is not defined then either the "default_sort()" function or ``canonical sorting'' (as defined by DNSSEC) will be used.
"rrsort()" returns a sorted array containing only elements of the specified RR type. Any other RR types are silently discarded.
"rrsort()" returns an empty list when arguments are incorrect.
See Net::DNS::Update for an example of performing dynamic updates.
use Net::DNS; my $res = Net::DNS::Resolver->new; my $reply = $res->search("www.example.com", "AAAA"); if ($reply) { foreach my $rr ($reply->answer) { print $rr->address, "\n" if $rr->can("address"); } } else { warn "query failed: ", $res->errorstring, "\n"; }
use Net::DNS; my $res = Net::DNS::Resolver->new; my $reply = $res->query("example.com", "NS"); if ($reply) { foreach $rr (grep { $_->type eq "NS" } $reply->answer) { print $rr->nsdname, "\n"; } } else { warn "query failed: ", $res->errorstring, "\n"; }
use Net::DNS; my $name = "example.com"; my $res = Net::DNS::Resolver->new; my @mx = mx($res, $name); if (@mx) { foreach $rr (@mx) { print $rr->preference, "\t", $rr->exchange, "\n"; } } else { warn "Can not find MX records for $name: ", $res->errorstring, "\n"; }
use Net::DNS; my $res = Net::DNS::Resolver->new; my $reply = $res->query("example.com", "SOA"); if ($reply) { foreach my $rr ($reply->answer) { $rr->print; } } else { warn "query failed: ", $res->errorstring, "\n"; }
use Net::DNS; my $res = Net::DNS::Resolver->new; $res->tcp_timeout(20); $res->nameservers("ns.example.com"); my @zone = $res->axfr("example.com"); foreach $rr (@zone) { $rr->print; } warn $res->errorstring if $res->errorstring;
use Net::DNS; my $res = Net::DNS::Resolver->new; $res->udp_timeout(10); $res->tcp_timeout(20); my $socket = $res->bgsend("host.example.com", "AAAA"); while ( $res->bgbusy($socket) ) { # do some work here while waiting for the response # ...and some more here } my $packet = $res->bgread($socket); if ($packet) { $packet->print; } else { warn "query failed: ", $res->errorstring, "\n"; }
For other items to be fixed, or if you discover a bug in this distribution please use the CPAN bug reporting system.
Portions Copyright (c)2002,2003 Chris Reinhardt.
Portions Copyright (c)2005 Olaf Kolkman (RIPE NCC)
Portions Copyright (c)2006 Olaf Kolkman (NLnet Labs)
Portions Copyright (c)2014 Dick Franks
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Between 2005 and 2012 Net::DNS was maintained by Olaf Kolkman.
Between 2002 and 2004 Net::DNS was maintained by Chris Reinhardt.
Net::DNS was created in 1997 by Michael Fuhr.