Use the Net: dns cpan module to simulate a DNS cname response record

Source: Internet
Author: User
Tags nameserver

Install net: DNS Module

Perl-mcpan-e "Install net: DNS"

Script Simulation

#!/usr/bin/perluse 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;

Execute scripts

Perl-W srv. pl

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.