Skip to content

Instantly share code, notes, and snippets.

@hakobe
Created August 1, 2011 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakobe/1118021 to your computer and use it in GitHub Desktop.
Save hakobe/1118021 to your computer and use it in GitHub Desktop.
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