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

Hi Monk

I have declared a variable
my $domain_name= "www.google.com";
Now what i want is when the perl program sends this domain name in a dns message, it should convert it as 0377777706676F6F676C6503636F6D00. Otherwise the Wireshark can't recognise it as www.google.com

Is there any function in perl to convert the domain name format data into the hexa format as shown above?

Plz suggest me
Regd's
Sanjay
  • Comment on How to convert the domain name format data into hexadecimal format?
  • Download Code

Replies are listed 'Best First'.
Re: How to convert the domain name format data into hexadecimal format?
by moritz (Cardinal) on Jul 21, 2008 at 12:28 UTC
    I don't know what you're doing wrong, but it works fine for me without any magic.

    I started wireshark, then typed perl -wle 'gethostbyname("www.google.com")', and wireshark showed me, among other stuff, a line with the protocol set to DNS, and the text Standard query A www.google.com in the Info field.

    So I suspect that your problem is somewhere else.

Re: How to convert the domain name format data into hexadecimal format?
by shmem (Chancellor) on Jul 21, 2008 at 14:01 UTC
    it should convert it as 0377777706676F6F676C6503636F6D00

    0377777706676F6F676C6503636F6D00 is the hex dump representation of the name part of the assembled DNS packet:

    0020 0a 02 80 22 00 35 00 28 96 13 f4 3b 01 00 00 01 ...".5.( ...; +.... 0030 00 00 00 00 00 00 03 77 77 77 06 67 6f 6f 67 6c .......w ww.g +oogl 0040 65 03 63 6f 6d 00 00 01 00 01 e.com... ..

    The above dump lines correspond to the the plaintext tree parts shown in the middle frame of the wireshark window:

    Answer RRs: 0 Additional RRs: 0 V Queries V www.google.com: type A, class IN Name: www.google.com Type: A (Host address) Class: IN (0x0001)

    So, as you see, the name is encoded in that packet as you require, as it is sent to the DNS server. Encoding that beforehand doesn't make sense. I guess you are having an XY problem. What are you trying to do, with what results?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

      Hi

      Thanks for your reply. But the problem is that.

      Suppose i have declared My $domain_Name="www.google.com". When i am sending the above domain name with other

      parameters of the dns message like type as A and class as IN. The wireshark decoded the above domain name as 7777772e676F6F676C652e636F6D.

      So it shows it as malformed data. When the above domain name decoded as 0377777706676F6F676C6503636F6D00, at that time the wireshark recognise it fine. SO is there any function in perl to convert the above domain name into the above hexa value so that the wireshark recognise it well.

      The problem in the hexa value is that the data "www" is decoded as 777777 then the "." is decoded as 2e(as 2e is the ascii value for "." char, here it should be 06 which is the ascii value for ACknowledge).

      Actually what i want is that i have fetch the Domain name from a database where it is stored in the format www.google.com. Then i store that domain name in a variable called my $Domain_Name. When i will send that Domain Name along with other data in a dns message,at time the wireshark should decoded it as

      0377777706676F6F676C6503636F6D00 instead of 7777772e676F6F676C652e636F6D. Plz suggest me is there any function for it in perl? So that before sending the

      Domain_Name to the wireshrk it converts it into(For example) the 0377777706676F6F676C6503636F6D00 for the case of www.google.com

      Regd's

      Sanjay

        When i am sending the above domain name with other parameters of the dns message like type as A and class as IN. The wireshark decoded the above domain name as 7777772e676F6F676C652e636F6D.

        What other parameters? How are you sending the query? How do you assemble it? What perl function from what package with what parameters are you using? Why do you need wireshark at all to retrieve domain names from a database and sending DNS queries? Why do you need to convert strings into their hexadecimal representation, if you are storing the names as plain text in the database?

        If you showed some code, I could perhaps do more than just making educated guesses. Please see How do I post a question effectively?.

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}