主机名与规范主机名 [英] Host Name Vs Canonical Host Name

查看:237
本文介绍了主机名与规范主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下主机名和规范主机名之间的区别吗?

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() will attempt to resolve the FQDN. Therefore, you would get foo.mycompany.com whereas getHostName() 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆