r68706 - in /branches/upstream/libnet-nslookup-perl: ./ current/ current/Changes current/MANIFEST current/META.yml current/Makefile.PL current/README current/lib/ current/lib/Net/ current/lib/Net/Nslookup.pm current/t/ current/t/nslookup.t
takaki at users.alioth.debian.org
takaki at users.alioth.debian.org
Tue Feb 15 05:05:05 UTC 2011
Author: takaki
Date: Tue Feb 15 05:04:58 2011
New Revision: 68706
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=68706
Log:
[svn-inject] Installing original source of libnet-nslookup-perl (1.19)
Added:
branches/upstream/libnet-nslookup-perl/
branches/upstream/libnet-nslookup-perl/current/
branches/upstream/libnet-nslookup-perl/current/Changes
branches/upstream/libnet-nslookup-perl/current/MANIFEST
branches/upstream/libnet-nslookup-perl/current/META.yml
branches/upstream/libnet-nslookup-perl/current/Makefile.PL
branches/upstream/libnet-nslookup-perl/current/README
branches/upstream/libnet-nslookup-perl/current/lib/
branches/upstream/libnet-nslookup-perl/current/lib/Net/
branches/upstream/libnet-nslookup-perl/current/lib/Net/Nslookup.pm
branches/upstream/libnet-nslookup-perl/current/t/
branches/upstream/libnet-nslookup-perl/current/t/nslookup.t
Added: branches/upstream/libnet-nslookup-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-nslookup-perl/current/Changes?rev=68706&op=file
==============================================================================
--- branches/upstream/libnet-nslookup-perl/current/Changes (added)
+++ branches/upstream/libnet-nslookup-perl/current/Changes Tue Feb 15 05:04:58 2011
@@ -1,0 +1,84 @@
+# ======================================================================
+# --- Net::Nslookup ---
+# ======================================================================
+
+# ----------------------------------------------------------------------
+# Version 1.19 October 22, 2009
+# ----------------------------------------------------------------------
+
+* Applied patch from adam_lounds at hotmail.com to do CNAME lookups (see
+ https://rt.cpan.org/Ticket/Display.html?id=50704). Not sure how
+ this was missed originally; it's kind of a stupid bug.
+
+# ----------------------------------------------------------------------
+# Version 1.18 April 15, 2008
+# ----------------------------------------------------------------------
+
+* Added some test changes, thanks to Alexandr Ciornii (see
+ http://rt.cpan.org/Ticket/Display.html?id=35062).
+
+# ----------------------------------------------------------------------
+# Version 1.17 April 2, 2008
+# ----------------------------------------------------------------------
+
+* Fixed tests to only lookup IPv4 addresses.
+
+# ----------------------------------------------------------------------
+# Version 1.16 August 11, 2004
+# ----------------------------------------------------------------------
+
+* Applied a patch from XXX implementing TXT lookups.
+
+# ----------------------------------------------------------------------
+# Version 1.15 October 22, 2003
+# ----------------------------------------------------------------------
+
+* Applied patch from Vladimir Cotfas <ulianov at ulianov.ca> to make
+ MX lookups return names by default instead of addresses, based
+ on the $MX_IS_NUMERIC class variable.
+
+# ----------------------------------------------------------------------
+# Version 1.14 May 22, 2003
+# ----------------------------------------------------------------------
+
+* Added support for PTR records. Requested by Scott Brooke
+ <sbrooke at ftdata.com>.
+
+# ----------------------------------------------------------------------
+# Version 1.13 May 19, 2003
+# ----------------------------------------------------------------------
+
+* Modified t/nslookup.t to skip all tests if the NO_NET environment
+ variable is set (mostly so I can test off line).
+
+* Added "server" nslookup parameter, which lets you specify a
+ nameserver (or nameservers) to use.
+ Requested by Victor Pereira <vpereira at modulo.com.br>.
+
+# ----------------------------------------------------------------------
+# Version 1.12 March 14, 2003
+# ----------------------------------------------------------------------
+
+* qslookup no longer barfs when passed nothing, or when passed
+ something non-existant. RT#1947
+
+* alarm is not implemented on Win32; added some (incomplete, I'm sure)
+ conditional logic to check the platform before setting an alarm.
+ Needs to be checked on MacOS (I'm assuming OS X will be Unix-like and
+ have alarm). Reported by Roland Bauer (not RTed).
+
+# ----------------------------------------------------------------------
+# Version 1.11 November 19, 2002
+# ----------------------------------------------------------------------
+
+* Defers loading Net::DNS until it needs it, so that simple lookups
+ will be faster.
+
+* Added qslookup, which uses Socket and the system's resolver to do
+ lookups.
+
+* Revamped test suite -- Does tests based on the contents of
+ /etc/hosts. This is (obviously) biased towards un*xen and will
+ need to take Win32 into account.
+
+# vim: set tw=70 ts=2 sw=2 fo=trcqo2n:
Added: branches/upstream/libnet-nslookup-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-nslookup-perl/current/MANIFEST?rev=68706&op=file
==============================================================================
--- branches/upstream/libnet-nslookup-perl/current/MANIFEST (added)
+++ branches/upstream/libnet-nslookup-perl/current/MANIFEST Tue Feb 15 05:04:58 2011
@@ -1,0 +1,7 @@
+Changes
+lib/Net/Nslookup.pm
+Makefile.PL
+MANIFEST This list of files
+META.yml
+README
+t/nslookup.t
Added: branches/upstream/libnet-nslookup-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-nslookup-perl/current/META.yml?rev=68706&op=file
==============================================================================
--- branches/upstream/libnet-nslookup-perl/current/META.yml (added)
+++ branches/upstream/libnet-nslookup-perl/current/META.yml Tue Feb 15 05:04:58 2011
@@ -1,0 +1,15 @@
+--- #YAML:1.0
+name: Net-Nslookup
+version: 1.19
+abstract: Provide nslookup(1)-like capabilities
+license: ~
+author:
+ - darren chamberlain <darren at cpan.org>
+generated_by: ExtUtils::MakeMaker version 6.42
+distribution_type: module
+requires:
+ Net::DNS: 0
+ Test::More: 0.45
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.3.html
+ version: 1.3
Added: branches/upstream/libnet-nslookup-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-nslookup-perl/current/Makefile.PL?rev=68706&op=file
==============================================================================
--- branches/upstream/libnet-nslookup-perl/current/Makefile.PL (added)
+++ branches/upstream/libnet-nslookup-perl/current/Makefile.PL Tue Feb 15 05:04:58 2011
@@ -1,0 +1,32 @@
+use strict;
+use ExtUtils::MakeMaker;
+
+my %PREREQ_PM = (
+ 'Net::DNS' => 0.00,
+ 'Test::More' => 0.45,
+);
+
+my %clean = (
+ 'FILES' => '$(DISTVNAME).tar$(SUFFIX) *.ppd'
+);
+
+my %ABSTRACT = ();
+if ($] >= 5.00503) {
+ %ABSTRACT = (
+ 'AUTHOR' => 'darren chamberlain <darren at cpan.org>',
+ 'ABSTRACT_FROM' => 'lib/Net/Nslookup.pm',
+ );
+}
+
+my %dist = (
+ PREOP => 'perldoc -t lib/Net/Nslookup.pm > README',
+);
+
+WriteMakefile(
+ 'NAME' => 'Net::Nslookup',
+ 'VERSION_FROM' => 'lib/Net/Nslookup.pm',
+ 'PREREQ_PM' => \%PREREQ_PM,
+ 'clean' => \%clean,
+ 'dist' => \%dist,
+ %ABSTRACT,
+);
Added: branches/upstream/libnet-nslookup-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-nslookup-perl/current/README?rev=68706&op=file
==============================================================================
--- branches/upstream/libnet-nslookup-perl/current/README (added)
+++ branches/upstream/libnet-nslookup-perl/current/README Tue Feb 15 05:04:58 2011
@@ -1,0 +1,78 @@
+NAME
+ Net::Nslookup - Provide nslookup(1)-like capabilities
+
+SYNOPSIS
+ use Net::Nslookup;
+ my @addrs = nslookup $host;
+
+ my @mx = nslookup(qtype => "MX", domain => "perl.org");
+
+DESCRIPTION
+ Net::Nslookup provides the capabilities of the standard UNIX command
+ line tool nslookup(1). Net::DNS is a wonderful and full featured module,
+ but quite often, all you need is `nslookup $host`. This module provides
+ that functionality.
+
+ Net::Nslookup exports a single function, called "nslookup". "nslookup"
+ can be used to retrieve A, PTR, CNAME, MX, and NS records.
+
+ 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");
+
+ "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* (or *qtype*) argument. If *server* is specified (it should be
+ an IP address, or a reference to an array of IP addresses), that server
+ 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. This form is significantly faster than
+ using the full version, as it doesn't load Net::DNS for this.
+
+ 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. If there is only one address returned (as is usually the
+ case), then, naturally, it will be the only one returned, regardless of
+ the calling context.
+
+ *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.
+
+ *server* should be a single IP address or a reference to an array of IP
+ addresses:
+
+ my @a = nslookup(host => 'boston.com', server => '4.2.2.1');
+
+ my @a = nslookup(host => 'boston.com', server => [ '4.2.2.1', '128.103.1.1' ])
+
+ By default, "nslookup" returns addresses when looking up MX records;
+ however, the Unix tool "nslookup" returns names. Set
+ $Net::Nslookup::MX_IS_NUMERIC to a true value to have MX lookups return
+ numbers instead of names. This is a change in behavior from previous
+ versions of "Net::Nslookup", and is more consistent with other DNS
+ tools.
+
+TIMEOUTS
+ Lookups timeout after $Net::Nslookup::TIMEOUT seconds (default 15). Set
+ this to something more reasonable for your site or script.
+
+DEBUGGING
+ Set $Net::Nslookup::DEBUG to a true value to get debugging messages
+ carped to STDERR.
+
+ Set $Net::Nslookup::DEBUG_NET_DNS to a true value to put Net::DNS into
+ debug mode.
+
+TODO
+ * Support for TXT and SOA records.
+
+AUTHOR
+ darren chamberlain <darren at cpan.org>
+
Added: branches/upstream/libnet-nslookup-perl/current/lib/Net/Nslookup.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-nslookup-perl/current/lib/Net/Nslookup.pm?rev=68706&op=file
==============================================================================
--- branches/upstream/libnet-nslookup-perl/current/lib/Net/Nslookup.pm (added)
+++ branches/upstream/libnet-nslookup-perl/current/lib/Net/Nslookup.pm Tue Feb 15 05:04:58 2011
@@ -1,0 +1,323 @@
+package Net::Nslookup;
+
+# -------------------------------------------------------------------
+# Net::Nslookup - Provide nslookup(1)-like capabilities
+# Copyright (C) 2002 darren chamberlain <darren at cpan.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; version 2.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307 USA
+# -------------------------------------------------------------------
+
+use strict;
+use vars qw($VERSION $DEBUG $DEBUG_NET_DNS @EXPORT $TIMEOUT $MX_IS_NUMERIC $WIN32);
+use base qw(Exporter);
+
+$VERSION = 1.19;
+ at EXPORT = qw(nslookup);
+$DEBUG = 0 unless defined $DEBUG;
+$DEBUG_NET_DNS = 0 unless defined $DEBUG_NET_DNS;
+$TIMEOUT = 15 unless defined $TIMEOUT;
+$MX_IS_NUMERIC = 0 unless defined $MX_IS_NUMERIC;
+
+# Win32 doesn't implement alarm; what about MacOS?
+# Added check based on bug report from Roland Bauer
+# (not RT'ed)
+$WIN32 = $^O =~ /win/i;
+
+use Carp;
+use Exporter;
+use Socket qw/ inet_ntoa inet_aton /;
+
+my %_lookups = (
+ 'a' => \&_lookup_a,
+ 'cname' => \&_lookup_cname,
+ 'mx' => \&_lookup_mx,
+ 'ns' => \&_lookup_ns,
+ 'ptr' => \&_lookup_ptr,
+ 'txt' => \&_lookup_txt,
+);
+
+# ----------------------------------------------------------------------
+# qslookup($term)
+#
+# "quick" nslookup, doesn't require Net::DNS.
+#
+# ----------------------------------------------------------------------
+# Bugs:
+#
+# * RT#1947 (Scott Schnieder)
+# The qslookup subroutine fails if no records for the domain
+# exist, because inet_ntoa freaks out about inet_aton not
+# returning anything.
+# ----------------------------------------------------------------------
+# Context!
+sub qslookup($) {
+ my $a = inet_aton $_[0];
+ return $a ? inet_ntoa $a : '';
+}
+
+# ----------------------------------------------------------------------
+# nslookup(%args)
+#
+# Does the actual lookup, deferring to helper functions as necessary.
+# ----------------------------------------------------------------------
+sub nslookup {
+ my $options = isa($_[0], 'HASH') ? shift : @_ % 2 ? { 'host', @_ } : { @_ };
+ my ($term, $type, $server, @answers, $sub);
+
+ # Some reasonable defaults.
+ $term = lc ($options->{'term'} ||
+ $options->{'host'} ||
+ $options->{'domain'} || return);
+ $type = lc ($options->{'type'} ||
+ $options->{'qtype'} || "A");
+ $server = $options->{'server'} || '';
+
+ eval {
+ local $SIG{ALRM} = sub { die "alarm\n" };
+ alarm $TIMEOUT unless $WIN32;
+ $sub = $_lookups{$type};
+ defined $sub ? @answers = $sub->($term, $server)
+ : die "Invalid type '$type'";
+ alarm 0 unless $WIN32;
+ };
+
+ if ($@) {
+ die "Bad things happened: $@"
+ unless $@ eq "alarm\n";
+ carp qq{Timeout: nslookup("type" => "$type", "host" => "$term")};
+ }
+
+ return $answers[0] if (@answers == 1);
+ return (wantarray) ? @answers : $answers[0];
+}
+
+sub _lookup_a {
+ my ($term, $server) = @_;
+
+ debug("Performing 'A' lookup on `$term'");
+ return qslookup($term);
+}
+
+sub _lookup_mx {
+ my ($term, $server) = @_;
+ my $res = ns($server);
+ my (@mx, $rr, @answers);
+
+ debug("Performing 'MX' lookup on `$term'");
+ @mx = mx($res, $term);
+
+ unless($MX_IS_NUMERIC) {
+ for $rr (@mx) { push(@answers, $rr->exchange); }
+ return @answers;
+ }
+
+ for $rr (@mx) {
+ push @answers, nslookup(type => "A", host => $rr->exchange);
+ }
+
+ return @answers;
+}
+
+sub _lookup_ns {
+ my ($term, $server) = @_;
+ my $res = ns($server);
+ my (@answers, $query, $rr);
+
+ debug("Performing 'NS' lookup on `$term'");
+
+ $query = $res->search($term, "NS") || return;
+ for $rr ($query->answer) {
+ push @answers, nslookup(type => "A", host => $rr->nsdname);
+ }
+
+ return @answers;
+}
+
+sub _lookup_cname {
+ my ($term, $server) = @_;
+ my $res = ns($server);
+ my (@answers, $query, $rr);
+
+ debug("Performing 'CNAME' lookup on `$term'");
+
+ $query = $res->search($term, "CNAME") || return;
+ for $rr ($query->answer) {
+ push @answers, $rr->cname;
+ }
+
+ return @answers;
+}
+
+sub _lookup_ptr {
+ my ($term, $server) = @_;
+ my $res = ns($server);
+ my (@answers, $query, $rr);
+
+ debug("Performing 'PTR' lookup on `$term'");
+
+ $query = $res->search($term, "PTR") || return;
+ for $rr ($query->answer) {
+ if ($rr->can('ptrdname')) {
+ push @answers, $rr->ptrdname;
+ }
+ }
+
+ return @answers;
+}
+
+sub _lookup_txt ($\@) {
+ my ($term, $server) = @_;
+ my $res = ns($server);
+ my (@answers, $query, $rr);
+
+ debug("Performing 'TXT' lookup on `$term'");
+
+ $query = $res->search($term, "TXT") || return;
+ for $rr ($query->answer) {
+ push @answers, $rr->rdatastr();
+ }
+
+ return @answers;
+}
+
+{
+ my %res;
+ sub ns {
+ my $server = shift || "";
+
+ unless (defined $res{$server}) {
+ require Net::DNS;
+ import Net::DNS;
+ $res{$server} = Net::DNS::Resolver->new(debug => $DEBUG_NET_DNS);
+
+ # $server might be empty
+ if ($server) {
+ if (ref($server) eq 'ARRAY') {
+ $res{$server}->nameservers(@$server);
+ }
+ else {
+ $res{$server}->nameservers($server);
+ }
+ }
+ }
+
+ return $res{$server};
+ }
+
+ sub dump_res {
+ require Data::Dumper;
+ return Data::Dumper::Dumper(\%res);
+ }
+}
+
+sub isa { &UNIVERSAL::isa }
+
+sub debug { carp @_ if ($DEBUG) }
+
+1;
+__END__
+
+=head1 NAME
+
+Net::Nslookup - Provide nslookup(1)-like capabilities
+
+=head1 SYNOPSIS
+
+ use Net::Nslookup;
+ my @addrs = nslookup $host;
+
+ my @mx = nslookup(qtype => "MX", domain => "perl.org");
+
+=head1 DESCRIPTION
+
+Net::Nslookup provides the capabilities of the standard UNIX command
+line tool nslookup(1). Net::DNS is a wonderful and full featured module,
+but quite often, all you need is `nslookup $host`. This module
+provides that functionality.
+
+Net::Nslookup exports a single function, called C<nslookup>.
+C<nslookup> can be used to retrieve A, PTR, CNAME, MX, and NS records.
+
+ 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");
+
+C<nslookup> takes a hash of options, one of which should be I<term>,
+and performs a DNS lookup on that term. The type of lookup is
+determined by the I<type> (or I<qtype>) argument. If I<server> is
+specified (it should be an IP address, or a reference to an array
+of IP addresses), that server will be used for lookups.
+
+If only a single argument is passed in, the type defaults to I<A>,
+that is, a normal A record lookup. This form is significantly faster
+than using the full version, as it doesn't load Net::DNS for this.
+
+If C<nslookup> is called in a list context, and there is more than one
+address, an array is returned. If C<nslookup> is called in a scalar
+context, and there is more than one address, C<nslookup> returns the
+first address. If there is only one address returned (as is usually
+the case), then, naturally, it will be the only one returned,
+regardless of the calling context.
+
+I<domain> and I<host> are synonyms for I<term>, and can be used to
+make client code more readable. For example, use I<domain> when
+getting NS records, and use I<host> for A records; both do the same
+thing.
+
+I<server> should be a single IP address or a reference to an array
+of IP addresses:
+
+ my @a = nslookup(host => 'boston.com', server => '4.2.2.1');
+
+ my @a = nslookup(host => 'boston.com', server => [ '4.2.2.1', '128.103.1.1' ])
+
+By default, C<nslookup> returns addresses when looking up MX records;
+however, the Unix tool C<nslookup> returns names. Set
+$Net::Nslookup::MX_IS_NUMERIC to a true value to have MX lookups
+return numbers instead of names. This is a change in behavior from
+previous versions of C<Net::Nslookup>, and is more consistent with
+other DNS tools.
+
+=head1 TIMEOUTS
+
+Lookups timeout after $Net::Nslookup::TIMEOUT seconds (default 15).
+Set this to something more reasonable for your site or script.
+
+=head1 DEBUGGING
+
+Set $Net::Nslookup::DEBUG to a true value to get debugging messages
+carped to STDERR.
+
+Set $Net::Nslookup::DEBUG_NET_DNS to a true value to put L<Net::DNS>
+into debug mode.
+
+=head1 TODO
+
+=over 4
+
+=item *
+
+Support for TXT and SOA records.
+
+=back
+
+=head1 AUTHOR
+
+darren chamberlain <darren at cpan.org>
+
Added: branches/upstream/libnet-nslookup-perl/current/t/nslookup.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-nslookup-perl/current/t/nslookup.t?rev=68706&op=file
==============================================================================
--- branches/upstream/libnet-nslookup-perl/current/t/nslookup.t (added)
+++ branches/upstream/libnet-nslookup-perl/current/t/nslookup.t Tue Feb 15 05:04:58 2011
@@ -1,0 +1,63 @@
+#!/usr/bin/perl -w
+# vim: set ft=perl:
+
+use strict;
+my ($ntests, $hostfile, %hosts, $host);
+my @windows_hosts_file_locations = qw(
+ c:/windows/hosts
+ c:/winnt/system32/hosts
+ C:/WINDOWS/system32/drivers/etc/hosts
+);
+
+use Test::More;
+
+if ($^O =~ /win32/i) {
+ for my $wf (@windows_hosts_file_locations) {
+ if (-e $wf) {
+ $hostfile = $wf;
+ last;
+ }
+ }
+}
+
+$hostfile ||= "/etc/hosts";
+
+# Populate %hosts
+unless (open HOSTS, $hostfile) {
+ plan skip_all => "Can't open $hostfile: $!";
+}
+
+while (<HOSTS>) {
+ s/#.*//;
+ next if /^\s*$/;
+
+ my ($ip, @hosts) = split /\s+/;
+
+ # Cribbed from Regexp::Common::net
+ next unless $ip =~ /^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})\.
+ (25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})\.
+ (25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})\.
+ (25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})$/x;
+
+ @hosts{@hosts} = ($ip) x @hosts;
+}
+
+close HOSTS;
+
+$ntests = (keys %hosts) + 1;
+plan tests => $ntests;
+
+use_ok("Net::Nslookup");
+
+SKIP: {
+ skip "No network" => ($ntests - 1)
+ if $ENV{'NO_NET'};
+
+ my ($l) = sort { $b <=> $a } map { length } keys %hosts;
+ my $fmt = '%-' . ($l + 5) . 's%s';
+ for $host (sort keys %hosts) {
+ my $addr = nslookup($host);
+
+ ok($addr eq $hosts{$host}, sprintf $fmt, $host, $hosts{$host});
+ }
+}
More information about the Pkg-perl-cvs-commits
mailing list