如何检查两个主机是否相同

发布于 2024-09-03 02:29:06 字数 194 浏览 4 评论 0原文

我刚刚遇到一个问题,我必须检查路径是否指向 Windows 共享。此问题的一部分是检查主机 A 是否与主机 B 相同。其中主机 A 和主机 B 可以是以下 {IPv4-Address、IPv6-Address、Hostname、FQDN} 之一。由于我不需要精确,因此在我的案例中解析和比较 IP 地址就足够了。

但理论上有没有一种方法可以检查主机是否相同?

I just came across an issue, where I had to check if a path points into a windows share. Part of this problem is to check if host A is the same as host B. Where host A and host B can be one of the following {IPv4-Address, IPv6-Address, Hostname, FQDN}. As I do not need to be exact it's enough to resolve and compare the IP-Addresses in my case.

But is there, theoretically, a method to check if the hosts are the same?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戴着白色围巾的女孩 2024-09-10 02:29:06

不,没有通用方法可以查看两个标识符(名称或地址)是否指向同一主机。一个示例:192.0.2.12001:db8::bad:dcaf。它们是一样的吗? (答案:看不出来)

互联网上没有通用的主机身份概念。有些协议有这样的概念,例如SSH(连接到主机,查看指纹是否match)或 HIP(测试密钥),但您依赖于为这些特定激活此协议机器。

一些启发式方法可能会有所帮助(例如,对机器进行指纹识别),但它会远未达到 100%。

No, there is no general method to see if two identifiers (names or addresses) go to the same host. One example: 192.0.2.1 and 2001:db8::bad:dcaf. Are they the same? (Answer: cannot tell)

There is no general concept of host identity in the Internet. Some protocols have such a concept, for instance SSH (connect to the hosts, see if the fingerprints match) or HIP (test the keys) but you depend on this protocol being activated for these specific machines.

Some heuristics may help (fingerprinting the machine, for instance) but it will be far from 100 %.

花辞树 2024-09-10 02:29:06

将两个地址传递给 getaddrinfo() 函数,并比较结果列表是否有匹配项。

与 gethostbyname() 不同,此函数将愉快地解析 IPv6 文字,并且还将返回与主机名关联的任何相关 AAAAA 记录。

Pass the two addresses into the getaddrinfo() function, and compare the resulting lists for any matches.

Unlike gethostbyname(), this function will happily parse IPv6 literals, and will also return any relevant A or AAAA records associated with a host name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文