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 the ldns version 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 when Net::LDNS was compiled. if it wasn't? calling to_idn throws 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.conf or 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. 😭

πŸ”₯ INSTANCE METHODS πŸ”₯

  • query($name, $type, $class) β€” send a query for that triple. if type or class aren't provided they default to A and IN respectively. returns a Net::LDNS::Packet or undef. it's giving "answer me or don't" πŸ’…
  • name2addr($name) β€” asks this resolver to look up A and AAAA records 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 do PTR lookups, 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. ✨
    • $callback must 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. Use axfr() instead. ⚠️ sets this resolver object up for a zone transfer of the specified domain. if $class isn't given, it defaults to IN.
  • axfr_next() β€” Deprecated. Use axfr() instead. ⚠️ gets the next RR in the zone transfer. axfr_start() must have been done before this is called, and after this is called axfr_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. Use axfr() 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. Use axfr() instead. ⚠️ if axfr_next() threw an exception, this method returns the Net::LDNS::Packet that made it do so. the packet's RCODE is likely to say what the problem was (for example, NOTAUTH or NXDOMAIN). 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