Skip to content

Instantly share code, notes, and snippets.

@horus
Created August 11, 2010 14:23
Show Gist options
  • Select an option

  • Save horus/519051 to your computer and use it in GitHub Desktop.

Select an option

Save horus/519051 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
# Dependence: Net::DNS
# To get correct answers, use TCP.
# I am not going to say more.
use strict;
use Net::DNS;
use Net::DNS::Nameserver;
my $resolver = Net::DNS::Resolver->new(
nameservers => [qw(8.8.8.8 4.2.2.1 4.2.2.5)],
usevc => 1,
debug => 1,
);
sub reply_handler {
my ($qname, $qclass, $qtype) = @_;
my $packet = $resolver->send($qname, $qtype, $qclass);
return (
$packet->header->rcode,
[ $packet->answer ],
[ $packet->authority ],
[ $packet->additional ],
);
}
my $ns = Net::DNS::Nameserver->new(
LocalAddr => "127.0.0.1",
LocalPort => 53,
ReplyHandler => \&reply_handler,
Verbose => 1,
) or 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