<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/env perl
# nslookup.pl Perl implementation of Linux 'nslookup' utility, suitable for use
#             in non-interactive mode on FreeBSD and other operating systems.
#
# Copyright (c) 2020 Graham Jenkins &lt;grahjenk@cpan.org&gt;. All rights reserved.
# This program is free software; you can redistribute it and/or modify it under
# the same terms as Perl itself. Revised: 2020-05-10

use strict;
use warnings;
use File::Basename;
use Getopt::Long;
use Net::Nslookup;
use vars qw($VERSION);
$VERSION=1.01;

# Collect options, check usage
my ($type,$secs,$host,$server)=("A",15,,);
GetOptions("query=s"=&gt;\$type,"timeout=i"=&gt;\$secs);
die "Usage: ".basename($0)." [-query=type] [-timeout=secs] name [server]\n".
    " e.g.: ".basename($0)." -query=A -timeout=1 myhost.net [8.8.8.8]\n"
  if( ($#ARGV&lt;0) or ($#ARGV&gt;1) );

# Get the response
my @result;
if ( defined($ARGV[1]) ) {
  @result=nslookup(host=&gt;"$ARGV[0]",type=&gt;"$type",timeout=&gt;"$secs",
                                                             server=&gt;"$ARGV[1]")
} else {
  @result=nslookup(host=&gt;"$ARGV[0]",type=&gt;"$type",timeout=&gt;"$secs")
}
 
# Print the result
if ( @result ) {
  foreach (@result) { print "$_\n" }
  exit(0);
} else {
  print STDERR "** Failed **\n";
  exit(1)
}

__END__

=head1 NAME

nslookup - a portable implentation of the Linux 'nslookup' utility

=head1 README

A perl implentation of the Linux 'nslookup' utility, suitable for use in
non-interactive mode on FreeBSD and other operating systems.

=head1 USAGE

nslookup [-query=type] [-timeout=secs] name [server]

Default values for 'query' and 'timeout' are "A" and "15".

=head1 SCRIPT CATEGORIES

UNIX/System_administration
Networking

=head1 AUTHOR

Graham Jenkins &lt;grahjenk@cpan.org&gt;

=head1 COPYRIGHT

Copyright (c) 2020 Graham Jenkins. All rights reserved.
This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.

=cut
</pre></body></html>