Net::LDNS(3pm)
β¨ NAME β¨
Net::LDNS π β a DNS-talking module based on the ldns C library. it's giving resolver energy, no cap. (documented over in User Contributed Perl Documentation, bestie π)
π¦ SYNOPSIS π¦
my $resolver = Net::LDNS->new('8.8.8.8');
my $packet = $resolver->query('www.iis.se');
say $packet->string;
likeβ¦ three lines and you're already talking to the actual DNS?? iconic. π
πΈ DESCRIPTION πΈ
Net::LDNS is your resolver bf. what's a resolver? so glad you asked π«Ά β it's the part of the system that's literally responsible for sending queries and receiving answers to them. that's the whole job. she sends, she receives, she slays. π
π EXPORTABLE FUNCTIONS π
lib_version()β hands you back theldnsversion string. yes she can be exported, but she's not by default (she's a little shy π).to_idn($name, ...)β takes a whole bunch of strings and returns a list of them converted to IDNA format. it assumes the strings were already converted to Perl's internal encoding before you called it, so pls do that first bestie. can be exported, but β again β not by default.
β οΈ this one needs GNU libidn to have been present whenNet::LDNSwas compiled. if it wasn't? callingto_idnthrows an exception. straight up. π
has_idn()β takes no arguments, gives no drama. returns true if libidn was around at compilation, false if not. vibe check on your build. β¨has_gost()β also takes no arguments. returns true if GOST support was present at compilation, false if not. β¨load_zonefile($filename)β loads all the resource records in a zone file and returns them as a list. the whole zone. every last one. π
π CLASS METHOD π
new($addr,...)β creates a new resolver object, main character style π. the deets, fr fr:- no arguments at all? it'll pick up nameserver addresses from your system configuration (
/etc/resolv.confor equivalent). auto-pilot. π - a single argument that is
undef? it will not know of any nameservers, and every attempt to send a query will throw exceptions. she's on airplane mode and there's no wifi. π - one or more arguments that aren't
undef? it tries to parse them as IPv4 and IPv6 addresses, and if that works they make up the list of servers to send queries to. π - an argument that can't be parsed as an IP address? exception thrown. not negotiable. π
- no arguments at all? it'll pick up nameserver addresses from your system configuration (
π₯ INSTANCE METHODS π₯
query($name, $type, $class)β send a query for that triple. if type or class aren't provided they default toAandINrespectively. returns aNet::LDNS::Packetorundef. it's giving "answer me or don't" πname2addr($name)β asks this resolver to look upAandAAAArecords for the given name and returns a list of the IP addresses (as strings). in scalar context? returns the number of addresses found. count 'em π§addr2name($addr)β takes an IP address, asks the resolver to doPTRlookups, returns the names found. in scalar context, returns the number of names found. reverse uno card πrecurse($flag)β returns the setting of the recursion flag. give it an argument and it's treated as a boolean, and the flag gets set accordingly.debug($flag)β gets, and optionally sets, the debug flag.dnssec($flag)β get and optionally sets the DNSSEC flag. πcd($flag)β get and optionally sets the CD flag.igntc($flag)β get and optionally sets the igntc flag.usevc($flag)β get and optionally sets the usevc flag.retry($count)β get and optionally set the number of retries. (she'll try again, she's persistent π«Ά)retrans($seconds)β get and optionally set the number of seconds between retries.port($port)β get and optionally set the destination port for requests.edns_size($size)β get and optionally set the EDNS0 UDP maximum size.axfr( $domain, $callback, $class )β perform an AXFR operation, a.k.a. the big zone transfer moment. β¨$callbackmust be a code reference. it gets called once for every received resource record, with the RR object as its one and only argument.- after every one of those calls, its return value gets examined β and if that value is false, the AXFR process gets aborted. π
- the return value of the
axfr()method itself is true if the transfer completed normally, and false if it was aborted because the callback returned a false value. - if anything goes wrong during the process, an exception will be thrown.
- for example, saving all the RRs received from an AXFR looks like this:
my @rrs;
$resolver->axfr( $domain, sub { my ($rr) = @_; push @rrs, $rr; return 1;} );
axfr_start($domain,$class)β Deprecated. Useaxfr()instead. β οΈ sets this resolver object up for a zone transfer of the specified domain. if$classisn't given, it defaults toIN.axfr_next()β Deprecated. Useaxfr()instead. β οΈ gets the next RR in the zone transfer.axfr_start()must have been done before this is called, and after this is calledaxfr_complete()should be used to check if there are more records to get. if there's any problem, an exception will be thrown. basically the sequence should be something like:
$res->axfr_start('example.org');
do {
push @rrlist, $res->axfr_next;
} until $res->axfr_complete;
axfr_complete()β Deprecated. Useaxfr()instead. β οΈ returns false if there's a started zone transfer with more records to get, and true if the started transfer has completed. are we done yet or nah πΈaxfr_last_packet()β Deprecated. Useaxfr()instead. β οΈ ifaxfr_next()threw an exception, this method returns theNet::LDNS::Packetthat made it do so. the packet'sRCODEis likely to say what the problem was (for example,NOTAUTHorNXDOMAIN). the receipts, literally π§Ύtimeout($time)β get and/or set the socket timeout for the resolver. (nobody's waiting forever, bestie β³)source($addr)β get and/or set the IP address the resolver should try to send its queries from.
okay that's the whole thing, you ate π β¨ all this documented under perl v5.42.3, dated 2026-08-19, in the classic Net::LDNS(3pm) flavour β go forth and resolve, queen ππ¦π
π¦ where this page comes from
- ubuntu stonking: libnet-ldns-perl 0.75-7build7 Β· 2-clause-BSD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms