Last active
February 4, 2017 09:54
-
-
Save saturn99/0eccf1e112161908d427a0495c3d8b51 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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Net::DNS::Nameserver; | |
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 (1 ) { | |
my ($ttl, $rdata) = (3600, "192.168.1.102"); | |
my $rr = new Net::DNS::RR("$qname $ttl $qclass $qtype $rdata"); | |
push @ans, $rr; | |
$rcode = "NOERROR"; | |
}elsif( $qname eq "foo.example.com" ) { | |
$rcode = "NOERROR"; | |
}else{ | |
$rcode = "NXDOMAIN"; | |
} | |
# mark the answer as authoritative (by setting the 'aa' flag | |
return ($rcode, \@ans, \@auth, \@add, { aa => 1 }); | |
} | |
my $ns = new Net::DNS::Nameserver( | |
LocalPort => 53, | |
LocalAddr => '192.168.1.102', | |
ReplyHandler => \&reply_handler, | |
Verbose => 1 | |
) || die "couldn't create nameserver object\n"; | |
$ns->main_loop; |
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
#!/usr/bin/perl | |
$|++; | |
use Net::DNS; | |
use Net::DNS::Nameserver; | |
my $res = Net::DNS::Resolver->new; | |
$res->nameservers('4.2.2.4'); | |
sub reply_handler { | |
my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_; | |
my ($rcode, @ans, @auth, @add); | |
print $qname."\n" ; | |
my $packet = $res->send($qname,$qtype); | |
my @t = $packet->answer ; | |
push @ans, @t; | |
$rcode = "NOERROR"; | |
foreach my $l (@ans){ | |
$$l{ttl}=1 if $$l{ttl} >= 1 ; | |
} | |
# mark the answer as authoritive (by setting the 'aa' flag | |
return ($rcode, \@ans, \@auth, \@add, { aa => 1 }); | |
} | |
my $ns = new Net::DNS::Nameserver( | |
LocalPort => 53, | |
ReplyHandler => \&reply_handler, | |
Verbose => 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
در ورژن جدیدتر باید
LocalAddr = > 'IPADDRESS'
مشخص یشه و بجای IPADDRESS ایپی قرار بگیرد