奋斗中拥有

人生是个积累的过程,总会有摔倒,即使跌倒了,也要懂得抓一把沙子在手里...

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

安装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


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/force_eagle/article/details/7385198
个人分类: DNS
上一篇转换pfb/pfm字体格式为otf
下一篇SSL Library Compare
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭