CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
perl: how to get reply from DNS server?

 



tokhi
New User

Nov 18, 2008, 11:20 AM

Post #1 of 1 (773 views)
perl: how to get reply from DNS server? Can't Post

Dear all,
I have write a part of code in perl which send a dns request to the dns server.
The question is how to get the reply from the dns server, I want this part of code to act like the dig unix command, a sooner reply appreciated, thank you.

Code
#!/usr/bin/perl 
use IO::Socket;
&dnsQueryPacket($ARGV[0],$ARGV[1]);

sub dnsQueryPacket{
my $hostname = $_[0];
# my @labels = split(/\./, $hostname) ; my $n = scalar(@labels) ; my $question = pack("(C/a*)$n C n2", @labels, 0, 1, 1) ;
my @labels;
my $nlabels = 0;

for (split /\./, $hostname) {
push @labels, length, $_;
$nlabels++;
}
my $n = scalar(@labels);

my $question = pack("(C/a*)$n C n2", @labels, 0, 1, 1) ;
print '$question: ', join("", unpack("(C/a*)$n C n2", $question) ), "\n";
#Hexadecimal format of the Query Part!
print '$question: ', join(" ", unpack("(H2)*", $question) ), "\n";
}
}

to run the script: perl script.pl www.google.com A

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives