- 论坛徽章:
- 27
|
本帖最后由 shijiang1130 于 2013-04-05 14:00 编辑
回复 6# hhs66317
把你的程序再组装一下是能用的。- #!/usr/bin/perl
- use strict;
- use warnings;
- use Net::DNS;
- use Net::DNS::Nameserver;
- my $ns = new Net::DNS::Nameserver(
- LocalAddr => [ '127.0.0.1' ],
- LocalPort => 53,
- ReplyHandler => \&reply_handler,
- Truncate => 0,
- # Verbose => 1
- ) || die "couldn't create nameserver object\n";
- $ns->main_loop;
- sub reply_handler {
- my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;
- print "$peerhost => $qname , $qclass , $qtype\n";
- my ($rcode, @ans, @auth, @add);
- my $res = Net::DNS::Resolver->new(
- nameservers => [qw(8.8.8.8 8.8.4.4)],
- usevc => 1,
- persistent_tcp => 1,
- );
- #$res->tcp_timeout(10);
- #$res->retry(10);
-
- my $answer = $res->send($qname, $qtype, $qclass);
-
- # print "#####################################\n";
- # print $res->print;
- # print "#####################################\n";
- if ($answer) {
- $rcode = $answer->header->rcode;
- @ans = $answer->answer;
- @auth = $answer->authority;
- @add = $answer->additional;
- return ($rcode, \@ans, \@auth, \@add);
- }
- else {
- $rcode = "NXDOMAIN";
- return ($rcode, \@ans, \@auth, \@add, { aa => 1, ra => 1 });
- }
- }
复制代码 |
|