Sorry if I misuse the Net::DNS.
I wrote a dig script with Net::DNS::Resolver->query(), it works when
debug=1, but when debug=0, it don't work. the same result if I
change query() to send().
digsoa.pl
=========== x ==========
#!/usr/bin/perl
require 5.002;
use strict;
use Carp;
use Net::DNS;
use Data::Dumper;
my($soa);
digsoa('203.119.25.1', 53, 'cn', \$soa);
print "$soa\n";
sub digsoa {
my($server, $port, $domain, $rsoa) = @_;
print STDERR "($server, $port, $domain, $rsoa)\n";
my($res) = Net::DNS::Resolver->new(
nameservers => [ $server ],
port => $port,
recurse => 0,
debug => 0,
);
my($packet);
$res->udp_timeout(9);
$res->retrans(3);
$res->retry(2);
$packet = $res->query($domain, 'SOA');
if(defined($packet)) {
print STDERR Data::Dumper->Dump([$packet]);
$$rsoa = $packet->{'answer'}->[0]->{'serial'};
return 1;
};
return 0;
}
=========== x ==========
when I add some lines on Packet.pm,
# diff -c Packet.pm_00 Packet.pm
*** Packet.pm_00 2009-12-30 19:01:39.000000000 +0800
--- Packet.pm 2011-10-08 20:13:41.000000000 +0800
***************
*** 122,127 ****
--- 122,132 ----
($self || die $@)->print if $debug;
+ #$self->question;
+ $self->answer;
+ $self->authority;
+ $self->additional;
+
return wantarray ? ($self, $@) : $self;
}
it works whether I set debug to 0 or 1.
# perl -v
This is perl, v5.8.8 built for x86_64-linux-thread-multi
Copyright 1987-2006, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source
kit.
Complete documentation for Perl, including FAQ lists, should be
found on
this system using "man perl" or "perldoc perl". If you have access to
the
Internet, point your browser at http://www.perl.org/, the Perl Home
Page.
# uname -a
Linux oldtest09.knet.cn 2.6.18-274.3.1.el5 #1 SMP Tue Sep 6
20:13:52 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release
CentOS release 5.7 (Final)