Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am trying to make DNS filter where I can send 'A' entry for some of the requested domains and redirect the request to a real DNS server if no domain matched.

I am stucked with the fact that tools like 'nslookup' send un-understandable characters to my perl script so I am unable to match anything and stopped working on the code until I get some help.

Here is my code:

use IO::Socket; my $server = IO::Socket::INET->new( Proto => 'udp', LocalPort => 53, ); die "Couldn't setup server: $@" unless $server; while ( $server->recv(my $data , 1024, my $flag ) ) { print "Got: $data\n"; }

Replies are listed 'Best First'.
Re: DNS filter
by Corion (Patriarch) on Feb 09, 2010 at 20:13 UTC

      Both appears to be complicated ... I have tried both of them but could not get what I need.

      Any idea why the dns request appears scrambled ?

      For example querying msn.com giving this output.

      �smsncom

      Is there any guide for implementing this, I looked at the source of the modules you mentioned and both are full of pack/unpack ...etc I do not want to copy and paste code all over ... I want to understand how it works.

        DNS is BINARY not ASCI, This site explains it http://www.firewall.cx/dns-query-format.php. But I think a better source is the DNS and BIND book.

        Your set up sounds like you just need a BIND server with a forwarder address, you can add your own zones with 'A' records as you see fit.