如何使用 dnspython 找到域的权威 DNS 服务器?
作为我正在编写的工具的一部分,我希望进行诊断,告诉用户他们是否已为特定服务正确配置了域的 DNS。我想查询权威 DNS 服务器的域,以便我可以绕过任何缓存的结果。
As part of a tool I'm writing I want to have a diagnostic that will tell the user whether they have configured their domain's DNS correctly for a particular service. I want to query the authoritative DNS server for their domain so that I can bypass any cached results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是我的尝试。它使用系统的标准 DNS 服务器来查找顶级域的根服务器,并解析链上各个 DNS 服务器的名称,我认为这是合适的,因为这些名称可能很少更改。
这是一些示例输出:
Here's my attempt at this. It uses the system's standard DNS server for looking up the root server for the top-level domain and for resolving the names of the various DNS servers along the chain, which I think is appropriate because those names would presumably change very infrequently.
Here's some sample output:
我遇到了 Jon Colverson 的答案,它帮助我理解了 dnspython 模块以及如何处理结果(我猜所有 DNS 模块都有相同的类结构的扭曲迷宫......)我需要 TTL 和粘合记录,所以我创建了我自己的改编。我将其发布在这里以防有人会发现它有用;我无意与乔恩·科尔弗森的出色答案竞争,只是补充一些额外的空白。基本改进是使用答案附加部分中可用的名称服务器信息。我想服务器可以在附加部分中放置除粘合记录之外的其他内容,因此也许仍应对其进行增强,以将附加部分中的信息与答案部分中的信息正确关联。我还获取并打印所有名称服务器,而不仅仅是第一个。
I came across Jon Colverson's answer, and it helped me understand the dnspython module and how to process the results (I guess all DNS modules have the same twisty maze of class structure ...) I needed the TTL and the glue records, so I created my own adaptation. I am posting it here in case somebody would find it useful; I do not intend to compete with Jon Colverson's excellent answer, just fill in some additional blanks. The basic improvement is the use of name server information from the additional section of the answer, where available. I suppose a server could put something else than glue records in the additional section, so perhaps this should still be enhanced to properly correlate the information from the additional section with the information in the answer section. I also fetch and print all the name servers, not just the first one.
其他示例很好,但如果您只需要名称服务器,则过于复杂。示例来自
http://c0deman.wordpress.com/ 2014/06/17/find-nameservers-of-domain-name-python/ :
The other examples are fine but overly complex if you need just the nameservers. Example from
http://c0deman.wordpress.com/2014/06/17/find-nameservers-of-domain-name-python/ :
我很确定这会成功。
您当然可以清理
这会产生的响应
Im pretty sure this would do it.
You could of course cleanup the response
This produces
我最终来到这里是因为我需要在 python 中获得 ns 的准确返回,忽略缓存并从随机服务器开始。
我从您的回答中得到了很多帮助,以构建对我来说最有用的版本。
它允许我直接知道一个站点是否属于某个域停车(例如 freespt.com => ['ns1.bodis.com.', 'ns2.bodis.com.'])
我希望我的代码是对你有用!
这会产生
I ended up here because I needed to get an accurate return of ns in python ignoring the cache and starting from random servers.
I got a lot of help from your answers to build what is for me, the most useful version.
It allows me to know directly if a site belongs to a domain parking or not (e.g. freespt.com => ['ns1.bodis.com.', 'ns2.bodis.com.'])
I hope my code will be useful to you!
This produces