Net::Nslookup(3pm)

πŸ“¦
version 2.04 Β· 2 versions
  • 2.04 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 2.04 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Net::Nslookup ✨

okay so bestie, this is a page from the User Contributed Perl Documentation section, and it's literally called Net::Nslookup β€” it's giving "I want nslookup energy but I'm writing Perl" and honestly? obsessed. πŸ’…


🌸 NAME 🌸

Net::Nslookup β€” it does the whole nslookup(1)-like thing. no cap. πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

use Net::Nslookup;
my @addrs = nslookup $host;

my @mx = nslookup(type => "MX", domain => "perl.org");

like. that's it. that's the whole vibe. ✨


πŸ’– DESCRIPTION πŸ’–

so Net::Nslookup gives you all the capabilities of the standard UNIX command line tool nslookup(1), bestie. and yes, Net::DNS is a wonderful and full featured module β€” it's iconic, it ate, no notes β€” but quite often all you actually need is nslookup $host. this module provides that functionality. periodt. πŸ’…

Net::Nslookup exports a single function, called nslookup. and nslookup can be used to retrieve A, PTR, CNAME, MX, NS, SOA, TXT, and SRV records. the range?? unmatched. πŸ‘‘

my $a  = nslookup(host => "use.perl.org", type => "A");

my @mx = nslookup(domain => "perl.org", type => "MX");

my @ns = nslookup(domain => "perl.org", type => "NS");

my $name = nslookup(host => "206.33.105.41", type => "PTR");

my @srv = nslookup(term => "_jabber._tcp.gmail.com", type => "SRV");

so nslookup takes a hash of options β€” one of which should be term β€” and performs a DNS lookup on that term. the type of lookup is determined by the type argument. and if server is specified (and it should be an IP address, or a reference to an array of IP addresses), then that server(s) will be used for lookups. 🫢

if only a single argument is passed in, the type defaults to A β€” that is, a normal A record lookup. classic. default behavior ate. 🌈

now listen, this part is important. if nslookup is called in a list context, and there is more than one address, an array is returned. if nslookup is called in a scalar context, and there is more than one address, nslookup returns the first address. and if there is only one address returned, then, naturally, it will be the only one returned, regardless of the calling context. the way that context just... decides your fate 😭✨

domain and host are synonyms for term, and can be used to make client code more readable. for example, use domain when getting NS records, and use host for A records; both do the same thing. pick whichever one gives the right vibe for your code, bestie. πŸŽ€

server should be a single IP address or a reference to an array of IP addresses:

my @a = nslookup(host => 'example.com', server => '4.2.2.1');

my @a = nslookup(host => 'example.com', server => [ '4.2.2.1', '128.103.1.1' ])

by default, when doing CNAME, MX, and NS lookups, nslookup returns names, not addresses. this is a change from versions prior to 2.0, which always tried to resolve names to addresses. glow-up behavior honestly. πŸ’– pass the recurse => 1 flag to nslookup to have it follow CNAME, MX, and NS lookups. and note that this usage of recurse is not consistent with the official DNS meaning of recurse β€” so don't come for me, that's just how it is. πŸ™ˆ

# returns soemthing like ("mail.example.com")
my @mx = nslookup(domain => 'example.com', type => 'MX');

# returns soemthing like ("127.0.0.1")
my @mx = nslookup(domain => 'example.com', type => 'MX', recurse => 1);

SOA lookups return the SOA record in the same format as the host tool:

print nslookup(domain => 'example.com', type => 'SOA');
dns1.icann.org. hostmaster.icann.org. 2011061433 7200 3600 1209600 3600

look at those numbers. slay. πŸ”₯


⏰ TIMEOUTS ⏰

lookups timeout after 15 seconds by default, but this can be configured by passing timeout => X to nslookup. so if you're impatient (same), you have options. πŸ’…


πŸ› DEBUGGING πŸ›

pass debug => 1 to nslookup to emit debugging messages to STDERR. main character debugging energy only. ✨


πŸ‘‘ AUTHOR πŸ‘‘

darren chamberlain <darren@cpan.org>


and that's the whole page, bestie! 🫢 this gem was documented for perl v5.36.0 and dated 2022-11-19 β€” go forth and nslookup responsibly. mwah. πŸ’–πŸŽ€πŸ¦‹