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?
——————————–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.
And output:
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
.
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
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?
——————————–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.
And output:
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
.
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