主机名与规范主机名 [英] Host Name Vs Canonical Host Name
问题描述
有人可以解释一下主机名和规范主机名之间的区别吗?
Can anyone please explain me the difference between Host Name and Canonical Host Name?
我当前正在使用InetAddress类使用IP地址获取主机名.我遇到了这两个API. 所以我只是想知道,我应该选择哪一个?
I am currently using InetAddress class to fetch host name using the IP Address. I came across these 2 APIs. So I am just wondering, which one I should opt for?
推荐答案
两者之间有一些区别:
-
getCanonicalHostName()
会尝试解析 FQDN .因此,您将获得 foo.mycompany.com ,而
getCanonicalHostName()
will attempt to resolve the FQDN. Therefore, you would get foo.mycompany.com whereasgetHostName()
might just return foo.
getCanonicalHostName()
将始终进行反向DNS查找,而getHostName()
如果在InetAddress
构造函数中提供了主机名,则将返回存储的主机名.
getCanonicalHostName()
will always do a reverse DNS lookup, whereas getHostName()
would return the stored hostname if you supplied one in the InetAddress
constructor.
如果您打算将IP地址映射到主机名,我怀疑您将要使用getCanonicalHostName()
.
I suspect you will be wanting to use getCanonicalHostName()
if you are intending to map IP addresses to host names.
这篇关于主机名与规范主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!