简体   繁体   English

DNS 数据包 IP 地址结构

[英]DNS Packet IP Address Structure

I have been writing a python program that builds a packet and sends the packet request to a dns server.我一直在编写一个构建数据包并将数据包请求发送到 dns 服务器的 python 程序。 I have a problem the IP address is stored in hex in a way that is difficult to understand.我有一个问题,IP 地址以难以理解的方式以十六进制存储。 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'.在十六进制字段中,它具有每次迭代的次数,前面有一个 3,因此 8.8.8.8 中的 8 在十六进制中表示为“38”。 Is there an easy way to make 38 in hex from integer type 8?有没有一种简单的方法可以从整数类型 8 以十六进制生成 38?

Wireshark DNS 数据包捕获

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 .您正在尝试查找与域名8.8.8.8关联的 IP。 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.我不确定你为什么要这样做——如果你有一个数字 IP,你不需要使用 DNS 将其转换为地址。

Domain names are represented as ASCII text, and 38 is ASCII code for the character 8 .域名以 ASCII 文本表示,而38是字符8的 ASCII 码。

From int 8 to hex 38, you'll need to go through a few conversions.从 int 8 到 hex 38,您需要进行一些转换。 From int to string, to decimal, to hex.从整数到字符串,到十进制,再到十六进制。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM