I was wondering if I needed to change the following code with my own data and numbers, for example my own DNS data, or if it would be fine leaving it?
use strict; use Net::DNS::Nameserver; # ip to bind dns server to my $BINDIP = "127.0.0.1"; my $BINDPORT = 53; my %spoof = ( 'microsoft.com' => '72.14.179.47', ); my @ns = qw/4.2.2.2 4.2.2.3/; my $hostsfile = "/etc/hosts"; open(HOSTS, "<$hostsfile") || die "Can't read $hostsfile: $!"; while (<HOSTS>) { if (/^\s*(\d+\.\d+\.\d+\.\d+)\s+([^#\s]+)/) { $spoof{lc($2)} = $1; } } close(HOSTS); my $resolver = new Net::DNS::Resolver( nameservers => \@ns, recurse => 1, ); sub uniq { my %seen; grep !$seen{$_}++, @_; } sub reply_handler { my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_; my ($rcode, @ans, @auth, @add); my $err = "NOERROR"; print "Received query from $peerhost to ". $conn->{sockhost}. "\n" +; $query->print; if ($spoof{lc($qname)}) { my ($ttl, $rdata) = (3600, $spoof{lc($qname)}); my $rr = new Net::DNS::RR("$qname $ttl $qclass $qtype $rdata") +; push @ans, $rr; } else { my $ret = $resolver->search($qname); if ($ret) { foreach my $rr ($ret->answer) { next unless $rr->type eq "A"; push @ans, @{$ret->{answer}}; } } else { $err = "NXDOMAIN"; } } @ans = uniq(@ans); return ($err, \@ans, \@auth, \@add, { aa => 1 }); } my $ns = new Net::DNS::Nameserver( LocalPort => $BINDPORT, LocalAddr => $BINDIP, ReplyHandler => \&reply_handler, Verbose => 1 ) || die "couldn't create nameserver object\n"; $ns->main_loop;
In reply to Perl networking DNS by b0b.5m1th.f4
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |