使用Net::DNS CPAN模块模拟一个DNS CNAME应答记录

标签: perlquery脚本object360
1893人阅读 评论(0) 收藏 举报
分类:

安装Net::DNS模块

perl -MCPAN -e "install Net::DNS"


模拟脚本

#!/usr/bin/perl

use Net::DNS::Nameserver;
use strict;
use warnings;

sub reply_handler {
     my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;
     my ($rcode, @ans, @auth, @add);

     print "Received query from $peerhost to ". $conn->{"sockhost"}. "\n";
     $query->print;

     if ($qtype eq "A" && $qname eq "www.ddos.com" ) {
         my ($ttl, $rdata) = (3600, "10.1.2.3");
         #push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");
         push @ans, Net::DNS::RR->new("www.ddos.com 0 IN CNAME guard.ddos.com");
         $rcode = "NOERROR";
     }elsif( $qname eq "www.ddos.com" ) {
         $rcode = "NOERROR";

     }else{
          $rcode = "NXDOMAIN";
     }

     # mark the answer as authoritive (by setting the 'aa' flag
     return ($rcode, \@ans, \@auth, \@add, { aa => 1 });
}

my $ns = Net::DNS::Nameserver->new(
            LocalPort    => 53,
            ReplyHandler => \&reply_handler,
            Verbose      => 1,
            ) || die "couldn't create nameserver object\n";

$ns->main_loop;
执行脚本

perl -w srv.pl


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1507963次
    • 积分:18522
    • 等级:
    • 排名:第489名
    • 原创:231篇
    • 转载:156篇
    • 译文:2篇
    • 评论:423条
    最新评论