DNS Packet IP Address Structure

Question:

I have been writing a python program that builds a packet and sends a reverse DNS lookup request to a DNS server. I have a problem the IP address is stored in hex in a way that is difficult to understand. In the hex field it has the number of each iteration with a 3 in front of it, so 8 in 8.8.8.8 is represented in hex as ’38’. Is there an easy way to make 38 in hex from integer type 8?

Wireshark DNS Packet Capture

——————————–UPDATE———————————

So I tried using struct.pack(‘c’, hex(ord()) and it is not packing those bytes as ASCII. I have listed a picture of the small block of code and output associated with it.

enter image description here

And output:

enter image description here

Asked By: AndroidAcolyteFX

||

Answers:

That’s not an address field, it’s the domain name field. You’re trying to look up the IP associated with the domain name 8.8.8.8. I’m not sure why you’re trying to do this — if you have a numeric IP, you don’t need to use DNS to translate it to an address.

Domain names are represented as ASCII text, and 38 is ASCII code for the character 8.

Answered By: Barmar

From int 8 to hex 38, you’ll need to go through a few conversions.
From int to string, to decimal, to hex.

For example: int 8 -> string = '8' -> ord('8') = 56 -> hex(56) = 0x38

Answered By: HWW
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.