API public String getCanonicalHostName()获取此 IP 地址的完全限定域名。最大努力方法,意味着根据基础系统配置可能不能返回 FQDN。 如果有安全管理器,则此方法首先使用主机名和 -1 作为参数调用其 checkConnect 方法,来查看是否允许调用代码知道此 IP 地址的主机名(即是否允许连接到该主机)。如果不允许该操作,则其返回 IP 地址的文本表示形式。 返回: 此 IP 地址的安全限定域名;如果安全检查不允许操作,则返回 IP 地址的文本表示形式。源代码private static String getHostFromNameService(InetAddress addr, boolean check) { String host; try { // first lookup the hostname host = nameService.getHostByAddr(addr.getAddress()); /* check to see if calling code is allowed to know * the hostname for this IP address, ie, connect to the host */ if (check) { SecurityManager sec = System.getSecurityManager(); if (sec != null) { sec.checkConnect(host, -1); } } /* now get all the IP addresses for this hostname, * and make sure one of them matches the original IP * address. We do this to try and prevent spoofing. */
InetAddress[] arr = InetAddress.getAllByName0(host, check); boolean ok = false; if(arr != null) { for(int i = 0; !ok && i < arr.length; i++) { ok = addr.equals(arr[i]); } } //XXX: if it looks a spoof just return the address? if (!ok) { host = addr.getHostAddress(); return host; } } catch (SecurityException e) { host = addr.getHostAddress(); } catch (UnknownHostException e) { host = addr.getHostAddress(); } return host; } FQDN:(Fully Qualified Domain Name)完全合格域名/全称域名,是指主机名加上全路径,全路径中列出了序列中所有域成员。全域名可以从逻辑上准确地表示出主机在什么地方,也可以说全域名是主机名的一种完全表示形式。从全域名中包含的信息可以看出主机在域名树中的位置。 详细的可以去百度
public String getCanonicalHostName()获取此 IP 地址的完全限定域名。最大努力方法,意味着根据基础系统配置可能不能返回 FQDN。
如果有安全管理器,则此方法首先使用主机名和 -1 作为参数调用其 checkConnect 方法,来查看是否允许调用代码知道此 IP 地址的主机名(即是否允许连接到该主机)。如果不允许该操作,则其返回 IP 地址的文本表示形式。
返回:
此 IP 地址的安全限定域名;如果安全检查不允许操作,则返回 IP 地址的文本表示形式。源代码private static String getHostFromNameService(InetAddress addr, boolean check) {
String host;
try {
// first lookup the hostname
host = nameService.getHostByAddr(addr.getAddress()); /* check to see if calling code is allowed to know
* the hostname for this IP address, ie, connect to the host
*/
if (check) {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkConnect(host, -1);
}
} /* now get all the IP addresses for this hostname,
* and make sure one of them matches the original IP
* address. We do this to try and prevent spoofing.
*/
InetAddress[] arr = InetAddress.getAllByName0(host, check);
boolean ok = false; if(arr != null) {
for(int i = 0; !ok && i < arr.length; i++) {
ok = addr.equals(arr[i]);
}
} //XXX: if it looks a spoof just return the address?
if (!ok) {
host = addr.getHostAddress();
return host;
} } catch (SecurityException e) {
host = addr.getHostAddress();
} catch (UnknownHostException e) {
host = addr.getHostAddress();
}
return host;
}
FQDN:(Fully Qualified Domain Name)完全合格域名/全称域名,是指主机名加上全路径,全路径中列出了序列中所有域成员。全域名可以从逻辑上准确地表示出主机在什么地方,也可以说全域名是主机名的一种完全表示形式。从全域名中包含的信息可以看出主机在域名树中的位置。
详细的可以去百度