
tokhi
New User
Nov 18, 2008, 11:20 AM
Post #1 of 1
(568 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.
#!/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
|