{
    "content": [
        {
            "type": "text",
            "text": "# Net::DNS (perldoc)\n\n## NAME\n\nNet::DNS - Perl Interface to the Domain Name System\n\n## SYNOPSIS\n\nuse Net::DNS;\n\n## DESCRIPTION\n\nNet::DNS is a collection of Perl modules that act as a Domain Name System (DNS) resolver. It\nallows the programmer to perform DNS queries that are beyond the capabilities of \"gethostbyname\"\nand \"gethostbyaddr\".\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (5 subsections)\n- **METHODS**\n- **Dynamic DNS Update Support**\n- **Zone Serial Number Management**\n- **Sorting of RR arrays**\n- **EXAMPLES** (6 subsections)\n- **BUGS**\n- **COPYRIGHT**\n- **LICENSE**\n- **AUTHOR INFORMATION**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Net::DNS",
        "section": "",
        "mode": "perldoc",
        "summary": "Net::DNS - Perl Interface to the Domain Name System",
        "synopsis": "use Net::DNS;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "The following brief examples illustrate some of the features of Net::DNS. The documentation for",
            "individual modules and the demo scripts included with the distribution provide more extensive",
            "examples.",
            "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->tcptimeout(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->udptimeout(10);",
            "$res->tcptimeout(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\";"
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 7,
                "subsections": [
                    {
                        "name": "Resolver Objects",
                        "lines": 4
                    },
                    {
                        "name": "Packet Objects",
                        "lines": 12
                    },
                    {
                        "name": "Update Objects",
                        "lines": 2
                    },
                    {
                        "name": "Header Object",
                        "lines": 3
                    },
                    {
                        "name": "Question Object",
                        "lines": 9
                    }
                ]
            },
            {
                "name": "METHODS",
                "lines": 45,
                "subsections": []
            },
            {
                "name": "Dynamic DNS Update Support",
                "lines": 87,
                "subsections": []
            },
            {
                "name": "Zone Serial Number Management",
                "lines": 24,
                "subsections": []
            },
            {
                "name": "Sorting of RR arrays",
                "lines": 33,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 6,
                "subsections": [
                    {
                        "name": "Look up host addresses.",
                        "lines": 12
                    },
                    {
                        "name": "Find the nameservers for a domain.",
                        "lines": 12
                    },
                    {
                        "name": "Find the MX records for a domain.",
                        "lines": 13
                    },
                    {
                        "name": "Print domain SOA record in zone file format.",
                        "lines": 12
                    },
                    {
                        "name": "Perform a zone transfer and print all the records.",
                        "lines": 13
                    },
                    {
                        "name": "Perform a background query and print the reply.",
                        "lines": 18
                    }
                ]
            },
            {
                "name": "BUGS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "AUTHOR INFORMATION",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 3,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Net::DNS - Perl Interface to the Domain Name System\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Net::DNS;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Net::DNS is a collection of Perl modules that act as a Domain Name System (DNS) resolver. It\nallows the programmer to perform DNS queries that are beyond the capabilities of \"gethostbyname\"\nand \"gethostbyaddr\".\n\nThe programmer should be familiar with the structure of a DNS packet. See RFC 1035 or DNS and\nBIND (Albitz & Liu) for details.\n",
                "subsections": [
                    {
                        "name": "Resolver Objects",
                        "content": "A resolver object is an instance of the Net::DNS::Resolver class. A program may have multiple\nresolver objects, each maintaining its own state information such as the nameservers to be\nqueried, whether recursion is desired, etc.\n"
                    },
                    {
                        "name": "Packet Objects",
                        "content": "Net::DNS::Resolver queries return Net::DNS::Packet objects. A packet object has five sections:\n\n*  header, represented by a Net::DNS::Header object\n\n*  question, a list of no more than one Net::DNS::Question object\n\n*  answer, a list of Net::DNS::RR objects\n\n*  authority, a list of Net::DNS::RR objects\n\n*  additional, a list of Net::DNS::RR objects\n"
                    },
                    {
                        "name": "Update Objects",
                        "content": "Net::DNS::Update is a subclass of Net::DNS::Packet useful for creating dynamic update requests.\n"
                    },
                    {
                        "name": "Header Object",
                        "content": "The Net::DNS::Header object mediates access to the header data which resides within the\ncorresponding Net::DNS::Packet.\n"
                    },
                    {
                        "name": "Question Object",
                        "content": "The Net::DNS::Question object represents the content of the question section of the DNS packet.\n\nRR Objects\nNet::DNS::RR is the base class for DNS resource record (RR) objects in the answer, authority,\nand additional sections of a DNS packet.\n\nDo not assume that RR objects will be of the type requested. The type of an RR object must be\nchecked before calling any methods.\n"
                    }
                ]
            },
            "METHODS": {
                "content": "Net::DNS exports methods and auxilliary functions to support DNS updates, zone serial number\nmanagement, and simple DNS queries.\n\nversion\nuse Net::DNS;\nprint Net::DNS->version, \"\\n\";\n\nReturns the version of Net::DNS.\n\nrr\n# Use a default resolver -- can not get an error string this way.\nuse Net::DNS;\nmy @rr = rr(\"example.com\");\nmy @rr = rr(\"example.com\", \"AAAA\");\nmy @rr = rr(\"example.com\", \"AAAA\", \"IN\");\n\n# Use your own resolver object.\nmy $res = Net::DNS::Resolver->new;\nmy @rr  = rr($res, \"example.com\" ... );\n\nmy ($ptr) = rr(\"2001:DB8::dead:beef\");\n\nThe \"rr()\" method provides simple RR lookup for scenarios where the full flexibility of Net::DNS\nis not required.\n\nReturns a list of Net::DNS::RR objects for the specified name or an empty list if the query\nfailed or no record was found.\n\nSee \"EXAMPLES\" for more complete examples.\n\nmx\n# Use a default resolver -- can not get an error string this way.\nuse Net::DNS;\nmy @mx = mx(\"example.com\");\n\n# Use your own resolver object.\nmy $res = Net::DNS::Resolver->new;\nmy @mx  = mx($res, \"example.com\");\n\nReturns a list of Net::DNS::RR::MX objects representing the MX records for the specified name.\nThe list will be sorted by preference. Returns an empty list if the query failed or no MX record\nwas found.\n\nThis method does not look up address records; it resolves MX only.\n",
                "subsections": []
            },
            "Dynamic DNS Update Support": {
                "content": "The Net::DNS module provides auxilliary functions which support dynamic DNS update requests.\n\n$update = Net::DNS::Update->new( 'example.com' );\n\n$update->push( prereq => nxrrset('example.com. AAAA') );\n$update->push( update => rradd('example.com. 86400 AAAA 2001::DB8::F00') );\n\nyxrrset\nUse this method to add an \"RRset exists\" prerequisite to a dynamic update packet. There are two\nforms, value-independent and value-dependent:\n\n# RRset exists (value-independent)\n$update->push( pre => yxrrset(\"host.example.com AAAA\") );\n\nMeaning: At least one RR with the specified name and type must exist.\n\n# RRset exists (value-dependent)\n$update->push( pre => yxrrset(\"host.example.com AAAA 2001:DB8::1\") );\n\nMeaning: At least one RR with the specified name and type must exist and must have matching\ndata.\n\nReturns a Net::DNS::RR object or \"undef\" if the object could not be created.\n\nnxrrset\nUse this method to add an \"RRset does not exist\" prerequisite to a dynamic update packet.\n\n$update->push( pre => nxrrset(\"host.example.com AAAA\") );\n\nMeaning: No RRs with the specified name and type can exist.\n\nReturns a Net::DNS::RR object or \"undef\" if the object could not be created.\n\nyxdomain\nUse this method to add a \"name is in use\" prerequisite to a dynamic update packet.\n\n$update->push( pre => yxdomain(\"host.example.com\") );\n\nMeaning: At least one RR with the specified name must exist.\n\nReturns a Net::DNS::RR object or \"undef\" if the object could not be created.\n\nnxdomain\nUse this method to add a \"name is not in use\" prerequisite to a dynamic update packet.\n\n$update->push( pre => nxdomain(\"host.example.com\") );\n\nMeaning: No RR with the specified name can exist.\n\nReturns a Net::DNS::RR object or \"undef\" if the object could not be created.\n\nrradd\nUse this method to add RRs to a zone.\n\n$update->push( update => rradd(\"host.example.com AAAA 2001:DB8::c001:a1e\") );\n\nMeaning: Add this RR to the zone.\n\nRR objects created by this method should be added to the \"update\" section of a dynamic update\npacket. The TTL defaults to 86400 seconds (24 hours) if not specified.\n\nReturns a Net::DNS::RR object or \"undef\" if the object could not be created.\n\nrrdel\nUse this method to delete RRs from a zone. There are three forms: delete all RRsets, delete an\nRRset, and delete a specific RR.\n\n# Delete all RRsets.\n$update->push( update => rrdel(\"host.example.com\") );\n\nMeaning: Delete all RRs having the specified name.\n\n# Delete an RRset.\n$update->push( update => rrdel(\"host.example.com AAAA\") );\n\nMeaning: Delete all RRs having the specified name and type.\n\n# Delete a specific RR.\n$update->push( update => rrdel(\"host.example.com AAAA 2001:DB8::dead:beef\") );\n\nMeaning: Delete the RR which matches the specified argument.\n\nRR objects created by this method should be added to the \"update\" section of a dynamic update\npacket.\n\nReturns a Net::DNS::RR object or \"undef\" if the object could not be created.\n",
                "subsections": []
            },
            "Zone Serial Number Management": {
                "content": "The Net::DNS module provides auxilliary functions which support policy-driven zone serial\nnumbering regimes.\n\n$soa->serial(SEQUENTIAL);\n$soa->serial(YYYMMDDxx);\n\nSEQUENTIAL\n$successor = $soa->serial( SEQUENTIAL );\n\nThe existing serial number is incremented modulo 232.\n\nUNIXTIME\n$successor = $soa->serial( UNIXTIME );\n\nThe Unix time scale will be used as the basis for zone serial numbering. The serial number will\nbe incremented if the time elapsed since the previous update is less than one second.\n\nYYYYMMDDxx\n$successor = $soa->serial( YYYYMMDDxx );\n\nThe 32 bit value returned by the auxilliary \"YYYYMMDDxx()\" function will be used as the base for\nthe date-coded zone serial number. Serial number increments must be limited to 100 per day for\nthe date information to remain useful.\n",
                "subsections": []
            },
            "Sorting of RR arrays": {
                "content": "\"rrsort()\" provides functionality to help you sort RR arrays. In most cases this will give you\nthe result that you expect, but you can specify your own sorting method by using the\n\"Net::DNS::RR::FOO->setrrsortfunc()\" class method. See Net::DNS::RR for details.\n\nrrsort\nuse Net::DNS;\n\nmy @sorted = rrsort( $rrtype, $attribute, @rrarray );\n\n\"rrsort()\" selects all RRs from the input array that are of the type defined by the first\nargument. Those RRs are sorted based on the attribute that is specified as second argument.\n\nThere are a number of RRs for which the sorting function is defined in the code.\n\nFor instance:\n\nmy @prioritysorted = rrsort( \"SRV\", \"priority\", @rrarray );\n\nreturns the SRV records sorted from lowest to highest priority and for equal priorities from\nhighest to lowest weight.\n\nIf the function does not exist then a numerical sort on the attribute value is performed.\n\nmy @portsorted = rrsort( \"SRV\", \"port\", @rrarray );\n\nIf the attribute is not defined then either the \"defaultsort()\" function or \"canonical sorting\"\n(as defined by DNSSEC) will be used.\n\n\"rrsort()\" returns a sorted array containing only elements of the specified RR type. Any other\nRR types are silently discarded.\n\n\"rrsort()\" returns an empty list when arguments are incorrect.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "The following brief examples illustrate some of the features of Net::DNS. The documentation for\nindividual modules and the demo scripts included with the distribution provide more extensive\nexamples.\n\nSee Net::DNS::Update for an example of performing dynamic updates.\n",
                "subsections": [
                    {
                        "name": "Look up host addresses.",
                        "content": "use Net::DNS;\nmy $res   = Net::DNS::Resolver->new;\nmy $reply = $res->search(\"www.example.com\", \"AAAA\");\n\nif ($reply) {\nforeach my $rr ($reply->answer) {\nprint $rr->address, \"\\n\" if $rr->can(\"address\");\n}\n} else {\nwarn \"query failed: \", $res->errorstring, \"\\n\";\n}\n"
                    },
                    {
                        "name": "Find the nameservers for a domain.",
                        "content": "use Net::DNS;\nmy $res   = Net::DNS::Resolver->new;\nmy $reply = $res->query(\"example.com\", \"NS\");\n\nif ($reply) {\nforeach $rr (grep { $->type eq \"NS\" } $reply->answer) {\nprint $rr->nsdname, \"\\n\";\n}\n} else {\nwarn \"query failed: \", $res->errorstring, \"\\n\";\n}\n"
                    },
                    {
                        "name": "Find the MX records for a domain.",
                        "content": "use Net::DNS;\nmy $name = \"example.com\";\nmy $res  = Net::DNS::Resolver->new;\nmy @mx   = mx($res, $name);\n\nif (@mx) {\nforeach $rr (@mx) {\nprint $rr->preference, \"\\t\", $rr->exchange, \"\\n\";\n}\n} else {\nwarn \"Can not find MX records for $name: \", $res->errorstring, \"\\n\";\n}\n"
                    },
                    {
                        "name": "Print domain SOA record in zone file format.",
                        "content": "use Net::DNS;\nmy $res   = Net::DNS::Resolver->new;\nmy $reply = $res->query(\"example.com\", \"SOA\");\n\nif ($reply) {\nforeach my $rr ($reply->answer) {\n$rr->print;\n}\n} else {\nwarn \"query failed: \", $res->errorstring, \"\\n\";\n}\n"
                    },
                    {
                        "name": "Perform a zone transfer and print all the records.",
                        "content": "use Net::DNS;\nmy $res  = Net::DNS::Resolver->new;\n$res->tcptimeout(20);\n$res->nameservers(\"ns.example.com\");\n\nmy @zone = $res->axfr(\"example.com\");\n\nforeach $rr (@zone) {\n$rr->print;\n}\n\nwarn $res->errorstring if $res->errorstring;\n"
                    },
                    {
                        "name": "Perform a background query and print the reply.",
                        "content": "use Net::DNS;\nmy $res    = Net::DNS::Resolver->new;\n$res->udptimeout(10);\n$res->tcptimeout(20);\nmy $socket = $res->bgsend(\"host.example.com\", \"AAAA\");\n\nwhile ( $res->bgbusy($socket) ) {\n# do some work here while waiting for the response\n# ...and some more here\n}\n\nmy $packet = $res->bgread($socket);\nif ($packet) {\n$packet->print;\n} else {\nwarn \"query failed: \", $res->errorstring, \"\\n\";\n}\n"
                    }
                ]
            },
            "BUGS": {
                "content": "Net::DNS is slow.\n\nFor other items to be fixed, or if you discover a bug in this distribution please use the CPAN\nbug reporting system.\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright (c)1997-2000 Michael Fuhr.\n\nPortions Copyright (c)2002,2003 Chris Reinhardt.\n\nPortions Copyright (c)2005 Olaf Kolkman (RIPE NCC)\n\nPortions Copyright (c)2006 Olaf Kolkman (NLnet Labs)\n\nPortions Copyright (c)2014 Dick Franks\n\nAll rights reserved.\n",
                "subsections": []
            },
            "LICENSE": {
                "content": "Permission to use, copy, modify, and distribute this software and its documentation for any\npurpose and without fee is hereby granted, provided that the original copyright notices appear\nin all copies and that both copyright notice and this permission notice appear in supporting\ndocumentation, and that the name of the author not be used in advertising or publicity\npertaining to distribution of the software without specific prior written permission.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING\nBUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\nDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
                "subsections": []
            },
            "AUTHOR INFORMATION": {
                "content": "Net::DNS is maintained at NLnet Labs (www.nlnetlabs.nl) by Willem Toorop.\n\nBetween 2005 and 2012 Net::DNS was maintained by Olaf Kolkman.\n\nBetween 2002 and 2004 Net::DNS was maintained by Chris Reinhardt.\n\nNet::DNS was created in 1997 by Michael Fuhr.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "perl, Net::DNS::Resolver, Net::DNS::Question, Net::DNS::RR, Net::DNS::Packet, Net::DNS::Update,\nRFC1035, <http://www.net-dns.org/>, *DNS and BIND* by Paul Albitz & Cricket Liu\n",
                "subsections": []
            }
        }
    }
}