Created
August 1, 2011 12:08
-
-
Save hakobe/1118021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Net::DNS::Nameserver; | |
sub reply_handler { | |
my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_; | |
my ($rcode, @ans, @auth, @add); | |
warn $qtype; | |
warn $qclass; | |
if ($qtype eq "A") { | |
my ($ttl, $rdata) = (3600, "127.0.0.1"); | |
push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata"); | |
$rcode = "NOERROR"; | |
} | |
else { | |
$rcode = 'NXDOMAIN'; | |
} | |
$query->print; | |
return ($rcode, \@ans, \@auth, \@add, { aa => 1 }); # 最後のフラグのいみがわかりません | |
} | |
my $ns = Net::DNS::Nameserver->new( | |
LocalAddr => '127.0.0.1', | |
LocalPort => "20059", | |
ReplyHandler => \&reply_handler, | |
Verbose => 1, | |
Truncate => 0, | |
) || die "couldn't create nameserver object\n"; | |
$ns->main_loop; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment