如何通过DNS记录区分域名和TLD
我需要确定用户输入的域是标准域(例如 example.co.uk
)还是 TLD(例如 co.uk
)。
有没有办法可以做到这一点,例如使用 nslookup 或 dig 命令查询名称服务器?
仅作为背景,我正在构建一个适用于子域(例如 sub.domain.example.co.uk
)的工具,并且需要能够将子域的每个部分拆分为子域、域和 TLD 部分。
谢谢,
汤姆
I need to determine whether a domain entered by a user is a standard domain e.g example.co.uk
or just the TLD e.g co.uk
.
Is there a way I can do this e.g. by querying nameservers using nslookup
or dig
commands?
Just for background, I'm building a tool which works with subdomains e.g. sub.domain.example.co.uk
and need to be able to spilt each part of the subdomain into subdomain, domain and TLD parts.
Thanks,
Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您试图解决的“问题”甚至没有明确定义。
无法从 DNS 本身获取此信息。 DNS 不区分子域、域和 TLD。
浏览器制造商和其他感兴趣的各方显然还没有找到任何解决方案来解决手动构建和维护列表的问题。即使这也是一个不完整的解决方案。例如,我知道在加拿大,您可以将域名注册为
.ca
、..ca
,或...ca
,但是 当前版本的 Mozilla 列表仅说明前两种可能性。 (无论如何,列出所有城市都太麻烦了)。更重要的是,“公共”域和“私有”域之间的界限不是技术上的界限。除非您是日本的大学(或类似机构),否则您不应该能够在
ac.jp
下注册域名。您不应该能够在u-tokyo.ac.jp
下注册域,除非您是东大(或类似机构)内的部门。这两种限制在技术层面上并没有本质上的不同,但其中一个域被认为是“公共”的,而另一个则不是。这是政治/法律的区别。此外,如果公共/私人领域的区别被用于安全目的(例如在网络浏览器中使用它来禁止超级cookie),谁说一所大学内的不同部门不会像不同大学那样相互不信任做?有一条众所周知的建议:你不应该试图用技术解决方案来解决政治问题。
The "problem" you are trying to solve isn't even well-defined.
There is no way to get this information from DNS itself. DNS makes no distinction between what you call a subdomain, a domain, and a TLD.
Browser makers and other interested parties have apparently not found any solution to this short of building and maintaining a list manually. And even that's an incomplete solution. For example, I know that in Canada you can register a domain as
<your-label>.ca
,<your-label>.<province>.ca
, or<your-label>.<municipality>.<province>.ca
, but the current version of Mozilla's list only accounts for the first two possibilities. (Listing all municipalities would be too burdensome anyway).More importantly, the boundary between what is a "public" domain and a "private" domain isn't a technical one. You're not supposed to be able to register a domain under
ac.jp
unless you are a university (or similar) in Japan. You're not supposed to be able to register a domain underu-tokyo.ac.jp
unless you are a department inside 東大 (or similar). Those two restrictions aren't fundamentally different on a technical level, yet one of those domains is considered "public" and the other one is not. It's a difference of politics/law.Furthermore, if the public/private domain distinction is being used for security purposes (as it is used for example in web browsers to disallow supercookies), who says that different departments inside one university don't distrust each other just as much as different universities do? There's a well known piece of advice that applies: you shouldn't attempt to solve a political problem with a technical solution.