url - 从 URL 获取子域

标签 url parsing dns subdomain

从 URL 获取子域一开始听起来很简单。

http://www.domain.example

扫描第一个句点,然后返回“http://”之后的内容...

那你还记得

http://super.duper.domain.example

哦。然后你想,好吧,找到最后一个句点,返回一个单词并获得之前的所有内容!

那你还记得

http://super.duper.domain.co.uk

你又回到了原点。除了存储所有顶级域名 (TLD) 的列表之外,还有什么好主意吗?

最佳答案

Anyone have any great ideas besides storing a list of all TLDs?

不可以,因为每个 TLD 的子域名、二级域名等的计算方式都不同。

请记住,存在顶级域、二级域和子域。从技术上讲,除了 TLD 之外的所有内容都是子域。

在domain.com.uk示例中,“domain”是子域,“com”是二级域,“uk”是TLD。

因此,问题仍然比乍一看更加复杂,并且取决于每个顶级域名 (TLD) 的管理方式。您需要一个包含所有 TLD 的数据库,其中包括其特定分区以及二级域名和子域名。不过,顶级域名 (TLD) 并不多,因此该列表相当易于管理,但收集所有这些信息并非易事。可能已经有这样的列表。

看起来像http://publicsuffix.org/就是这样一个列表 - 适合搜索的列表中的所有常见后缀(.com、.co.uk 等)。解析它仍然不容易,但至少您不必维护该列表。

A "public suffix" is one under which Internet users can directly register names. Some examples of public suffixes are ".com", ".co.uk" and "pvt.k12.wy.us". The Public Suffix List is a list of all known public suffixes.

The Public Suffix List is an initiative of the Mozilla Foundation. It is available for use in any software, but was originally created to meet the needs of browser manufacturers. It allows browsers to, for example:

  • Avoid privacy-damaging "supercookies" being set for high-level domain name suffixes
  • Highlight the most important part of a domain name in the user interface
  • Accurately sort history entries by site

Looking through the list ,你会发现这不是一个小问题。我认为列表是实现这一目标的唯一正确方法......

关于url - 从 URL 获取子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/288810/

相关文章:

java - Spring:添加查询参数的惯用方式

php - VirusTotal 服务 API 始终返回响应代码 1

ios - 将 JSON(日期)解析为 Swift

python - 解析带有特殊标记的文本文件

json - 验证大型 JSON key

amazon-web-services - 在 Amazon Route 53 中更好地使用加权循环路由

windows - Docker-通过编辑 “docker”文件添加DNS

python - 如何在python google app engine中将资源添加到url

vb.net - 从 URI 启动应用程序 - VB.NET

Nginx 反向代理,只允许从主机名而不是 ip 连接