<LI><A HREF="#look up a host's addresses.">Look up a host's addresses.</A></LI>
<LI><A HREF="#find the nameservers for a domain.">Find the nameservers for a domain.</A></LI>
<LI><A HREF="#find the mx records for a domain.">Find the MX records for a domain.</A></LI>
<LI><A HREF="#print a domain's soa record in zone file format.">Print a domain's SOA record in zone file format.</A></LI>
<LI><A HREF="#perform a zone transfer and print all the records.">Perform a zone transfer and print all the records.</A></LI>
<LI><A HREF="#perform a background query and do some other work while waiting">Perform a background query and do some other work while waiting</A></LI>
<LI><A HREF="#send a background query and use select to determine when the answer">Send a background query and use select to determine when the answer</A></LI>
<P>Meaning: Delete all RRs having the specified name.</P>
<PRE>
# Delete an RR.
$packet->push("update", rr_del("foo.bar.com A 10.1.2.3"));</PRE>
<P>Meaning: Delete all RRs having the specified name, type, and data.</P>
<P>RR objects created by this method should be added to the ``update''
section of a dynamic update packet.</P>
<P>Returns a <CODE>Net::DNS::RR</CODE> object or <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> if the object couldn't
be created.</P>
<P>
<HR>
<H1><A NAME="examples">EXAMPLES</A></H1>
<P>The following examples show how to use the <CODE>Net::DNS</CODE> modules.
See the other manual pages and the demo scripts included with the
source code for additional examples.</P>
<P>See the <CODE>Net::DNS::Update</CODE> manual page for an example of performing
dynamic updates.</P>
<P>
<H2><A NAME="look up a host's addresses.">Look up a host's addresses.</A></H2>
<PRE>
use Net::DNS;
$res = new Net::DNS::Resolver;
$query = $res->search("foo.bar.com");
if ($query) {
foreach $rr ($query->answer) {
next unless $rr->type eq "A";
print $rr->address, "\n";
}
}
else {
print "query failed: ", $res->errorstring, "\n";
}</PRE>
<P>
<H2><A NAME="find the nameservers for a domain.">Find the nameservers for a domain.</A></H2>
<PRE>
use Net::DNS;
$res = new Net::DNS::Resolver;
$query = $res->query("foo.com", "NS");
if ($query) {
foreach $rr ($query->answer) {
next unless $rr->type eq "NS";
print $rr->nsdname, "\n";
}
}
else {
print "query failed: ", $res->errorstring, "\n";
}</PRE>
<P>
<H2><A NAME="find the mx records for a domain.">Find the MX records for a domain.</A></H2>
<PRE>
use Net::DNS;
$name = "foo.com";
$res = new Net::DNS::Resolver;
@mx = mx($res, $name);
if (@mx) {
foreach $rr (@mx) {
print $rr->preference, " ", $rr->exchange, "\n";
}
}
else {
print "can't find MX records for $name: ", $res->errorstring, "\n";
}</PRE>
<P>
<H2><A NAME="print a domain's soa record in zone file format.">Print a domain's SOA record in zone file format.</A></H2>
<PRE>
use Net::DNS;
$res = new Net::DNS::Resolver;
$query = $res->query("foo.com", "SOA");
if ($query) {
($query->answer)[0]->print;
}
else {
print "query failed: ", $res->errorstring, "\n";
}</PRE>
<P>
<H2><A NAME="perform a zone transfer and print all the records.">Perform a zone transfer and print all the records.</A></H2>
<PRE>
use Net::DNS;
$res = new Net::DNS::Resolver;
$res->nameservers("ns.foo.com");
@zone = $res->axfr("foo.com");
foreach $rr (@zone) {
$rr->print;
}</PRE>
<P>
<H2><A NAME="perform a background query and do some other work while waiting for the answer.">Perform a background query and do some other work while waiting
for the answer.</A></H2>
<PRE>
use Net::DNS;
$res = new Net::DNS::Resolver;
$socket = $res->bgsend("foo.bar.com");
until ($res->bgisready($socket)) {
# do some work here while waiting for the answer
# ...and some more here
}
$packet = $res->bgread($socket);
$packet->print;</PRE>
<P>
<H2><A NAME="send a background query and use select to determine when the answer has arrived.">Send a background query and use select to determine when the answer
has arrived.</A></H2>
<PRE>
use Net::DNS;
use IO::Select;
$timeout = 5;
$res = new Net::DNS::Resolver;
$bgsock = $res->bgsend("foo.bar.com");
$sel = new IO::Select($bgsock);
# Add more sockets to $sel if desired.
@ready = $sel->can_read($timeout);
if (@ready) {
foreach $sock (@ready) {
if ($sock == $bgsock) {
$packet = $res->bgread($bgsock);
$packet->print;
$bgsock = undef;
}
# Check for the other sockets.
$sel->remove($sock);
$sock = undef;
}
}
else {
print "timed out after $timeout seconds\n";
}</PRE>
<P>
<HR>
<H1><A NAME="bugs">BUGS</A></H1>
<P><CODE>Net::DNS</CODE> is slow. Real slow.</P>
<P>For other items to be fixed, please see the TODO file included with
the source distribution.</P>
<P>
<HR>
<H1><A NAME="copyright">COPYRIGHT</A></H1>
<P>Copyright (c) 1997 Michael Fuhr. All rights reserved. This program is free
software; you can redistribute it and/or modify it under the same terms as