Skip to content
Advertisement

DNS Packet IP Address Structure

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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement