迭代 DNS 查找
Iterative DNS lookup
我正在尝试使用 python 将 dig 的简单版本实现为一个项目。我想通过迭代实现 DNS 查找。我阅读了 RFC 文档,我想我应该检查响应中的 AA(权威答案)位,如果它没有设置为 1,我应该向给定响应中提供的 IP 发送相同的请求,直到该位为放。
当我尝试 google.com 并使用 wireshark 检查响应时,它提供了正确的 IP,但 AA 位仍然为 0,当我继续发送请求时,它似乎无处可去。
这是进行迭代查找的正确方法吗?如果是这样,如何区分权威和非权威答案?
这是向 1.1.1.1 服务器请求 google.com:
时的结果
Flags: 0x8080 Standard query response, No error
1... .... .... .... = Response: Message is a response
.000 0... .... .... = Opcode: Standard query (0)
.... .0.. .... .... = Authoritative: Server is not an authority for domain
.... ..0. .... .... = Truncated: Message is not truncated
.... ...0 .... .... = Recursion desired: Don't do query recursively
.... .... 1... .... = Recursion available: Server can do recursive queries
.... .... .0.. .... = Z: reserved (0)
.... .... ..0. .... = Answer authenticated: Answer/authority portion was not authenticated by the server
.... .... ...0 .... = Non-authenticated data: Unacceptable
.... .... .... 0000 = Reply code: No error (0)
Here's the result when asking 1.1.1.1 server for google.com:
DNS 查询并不总是以权威答案结尾。实际上,1.1.1.1
是一个迭代解析器,所以查询相关服务器(root
->.com
-> google.com
)和return是他的工作最终答案不会是权威的,因为 1.1.1.1
是 return 的答案。然后它将缓存响应并 return 每当有人问他同样的问题时。
如果你想创建一个类似挖掘的工具并寻找 www.whosebug.com
,你需要做 1.1.1.1
做的事情 - 从根开始(例如 a.root-servers.net.
),并且询问 .com
。然后询问 .com
服务器(例如 a.gtld-servers.net
)关于 whosebug.com
。最后,向负责whosebug.com
(例如ns-1033.awsdns-01.org
)的服务器询问www.whosebug.com
的A
/AAAA
记录。你得到的答案应该是权威的:
> dig www.whosebug.com @ns-1033.awsdns-01.org ──(Thu,Apr08)─┘
; <<>> DiG 9.16.1-Ubuntu <<>> www.whosebug.com @ns-1033.awsdns-01.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62794
;; flags: qr aa rd; QUERY: 1, ANSWER: 5, AUTHORITY: 4, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.whosebug.com. IN A
;; ANSWER SECTION:
www.whosebug.com. 3600 IN CNAME whosebug.com.
whosebug.com. 3600 IN A 151.101.65.69
whosebug.com. 3600 IN A 151.101.1.69
whosebug.com. 3600 IN A 151.101.193.69
whosebug.com. 3600 IN A 151.101.129.69
;; AUTHORITY SECTION:
whosebug.com. 172800 IN NS ns-1033.awsdns-01.org.
whosebug.com. 172800 IN NS ns-358.awsdns-44.com.
whosebug.com. 172800 IN NS ns-cloud-e1.googledomains.com.
whosebug.com. 172800 IN NS ns-cloud-e2.googledomains.com.
注意 aa
标志:flags: qr aa rd
我正在尝试使用 python 将 dig 的简单版本实现为一个项目。我想通过迭代实现 DNS 查找。我阅读了 RFC 文档,我想我应该检查响应中的 AA(权威答案)位,如果它没有设置为 1,我应该向给定响应中提供的 IP 发送相同的请求,直到该位为放。 当我尝试 google.com 并使用 wireshark 检查响应时,它提供了正确的 IP,但 AA 位仍然为 0,当我继续发送请求时,它似乎无处可去。 这是进行迭代查找的正确方法吗?如果是这样,如何区分权威和非权威答案? 这是向 1.1.1.1 服务器请求 google.com:
时的结果Flags: 0x8080 Standard query response, No error
1... .... .... .... = Response: Message is a response
.000 0... .... .... = Opcode: Standard query (0)
.... .0.. .... .... = Authoritative: Server is not an authority for domain
.... ..0. .... .... = Truncated: Message is not truncated
.... ...0 .... .... = Recursion desired: Don't do query recursively
.... .... 1... .... = Recursion available: Server can do recursive queries
.... .... .0.. .... = Z: reserved (0)
.... .... ..0. .... = Answer authenticated: Answer/authority portion was not authenticated by the server
.... .... ...0 .... = Non-authenticated data: Unacceptable
.... .... .... 0000 = Reply code: No error (0)
Here's the result when asking 1.1.1.1 server for google.com:
DNS 查询并不总是以权威答案结尾。实际上,1.1.1.1
是一个迭代解析器,所以查询相关服务器(root
->.com
-> google.com
)和return是他的工作最终答案不会是权威的,因为 1.1.1.1
是 return 的答案。然后它将缓存响应并 return 每当有人问他同样的问题时。
如果你想创建一个类似挖掘的工具并寻找 www.whosebug.com
,你需要做 1.1.1.1
做的事情 - 从根开始(例如 a.root-servers.net.
),并且询问 .com
。然后询问 .com
服务器(例如 a.gtld-servers.net
)关于 whosebug.com
。最后,向负责whosebug.com
(例如ns-1033.awsdns-01.org
)的服务器询问www.whosebug.com
的A
/AAAA
记录。你得到的答案应该是权威的:
> dig www.whosebug.com @ns-1033.awsdns-01.org ──(Thu,Apr08)─┘
; <<>> DiG 9.16.1-Ubuntu <<>> www.whosebug.com @ns-1033.awsdns-01.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62794
;; flags: qr aa rd; QUERY: 1, ANSWER: 5, AUTHORITY: 4, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.whosebug.com. IN A
;; ANSWER SECTION:
www.whosebug.com. 3600 IN CNAME whosebug.com.
whosebug.com. 3600 IN A 151.101.65.69
whosebug.com. 3600 IN A 151.101.1.69
whosebug.com. 3600 IN A 151.101.193.69
whosebug.com. 3600 IN A 151.101.129.69
;; AUTHORITY SECTION:
whosebug.com. 172800 IN NS ns-1033.awsdns-01.org.
whosebug.com. 172800 IN NS ns-358.awsdns-44.com.
whosebug.com. 172800 IN NS ns-cloud-e1.googledomains.com.
whosebug.com. 172800 IN NS ns-cloud-e2.googledomains.com.
注意 aa
标志:flags: qr aa rd