我通过perl构建小脚本来通过转发请求到其他DNS服务器来回答所有DNS请求
use Net::DNS::Nameserver;
sub SendRequestToRemoteDNS {
my ($qname, $qtype, $qclass) = @_;
my ($dquery, $rcode, @ans, @auth, @add );
my $res = Net::DNS::Resolver->new (
nameservers => [ '8.8.8.8'],
port => 53,
recurse => 1,
debug => 0,
);
$dquery = $res->search($qname, $qtype, $qclass);
$rcode = 'NXDOMAIN';
if ($dquery){
$rcode = $dquery->header->rcode;
@ans = $dquery->answer;
@auth = $dquery->authority;
@add = $dquery->additional;
}
return ($rcode, \@ans, \@auth, \@add);
}
sub reply_handler {
my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;
SendRequestToRemoteDNS ($qname, $qtype, $qclass);
}
my $nameserver = new Net::DNS::Nameserver(
LocalAddr => '127.0.0.1',
LocalPort => 53,
ReplyHandler => \&reply_handler
);
有没有办法更改我的脚本以支持多线程请求? 这就像处理每个请求作为单独的线程! 感谢