forked from lepe/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns_server
executable file
·36 lines (28 loc) · 868 Bytes
/
dns_server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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 ($qtype eq "A" && $qname eq "foo.example.com" ) {
my ($ttl, $rdata) = (3600, "10.1.2.3");
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 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 => 1
) || die "couldn't create nameserver object\n";
$ns->main_loop;