in reply to How to convert the domain name format data into hexadecimal format?

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}

Replies are listed 'Best First'.
Re^2: How to convert the domain name format data into hexadecimal format?
by Anonymous Monk on Jul 22, 2008 at 06:10 UTC

    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}