Skip to content

Instantly share code, notes, and snippets.

@saturn99
Last active February 4, 2017 09:54
Show Gist options
  • Save saturn99/0eccf1e112161908d427a0495c3d8b51 to your computer and use it in GitHub Desktop.
Save saturn99/0eccf1e112161908d427a0495c3d8b51 to your computer and use it in GitHub Desktop.
#!/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;
#!/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;
@saturn99
Copy link
Author

saturn99 commented Feb 4, 2017

در ورژن جدیدتر باید
LocalAddr = > 'IPADDRESS'
مشخص یشه و بجای IPADDRESS ایپی قرار بگیرد

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment