问题可能是多方面原因造成的。
Reason 1: the IP address doesn t have a hostname
这可能是最常见的原因,与安保管理人员毫无关系。
如果IP地址不向东道方表示决心,因为没有东道方名称,那么你将期望getHostName(
>null或扔下<> Un knownHostException,但情况并非如此。 相反,getHostName()
简单地将IP地址重新定位为背后。 由于我所不知的原因,这一共同局势没有记载。
因此,如果IP地址与getHostName(
)所返还的结果相同,那么,东道方名称就不存在。
Detailed explanation
The following JDK code is the cause of this undocumented problem:
https://github.com/openjdk/jdk/blob/jdk-17+35/src/java.base/share/classes/java/net/InetAddress.java#L697
public class InetAddress implements java.io.Serializable {
private static String getHostFromNameService(InetAddress addr, boolean check) {
String host = null;
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) {
@SuppressWarnings("removal")
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();
// let next provider resolve the hostname
}
return host;
}
}
因此,所发生的情况是,IP-address被通过到。 姓名服务。
Lookup the host corresponding to the IP address provided
@param addr byte array representing an IP address
@return {@code String} representing the host name mapping
@throws UnknownHostException if no host found for the specified IP address
dNameservice.getHostByAddr(
>,在IP没有东道方名但的情况下,将“无名HostException
。 InetAddress.getHostFromNameservice() 吞s了这一例外,而是回到了所提供的IP-address本身!! 海事组织本应放弃这一例外,而不是吞.,因为吞.使客户更难确定是否存在东道名称。
You can check if the IP address has a hostname by using the nslookup
commandline tool: nslookup 192.168.2.139
. If it returns something like:
** server can t find 139.2.168.192.in-addr.arpa: NXDOMAIN
(Linux) or *** can t find 192.168.2.139: Non-existent domain
(Windows) then there is no hostname.
Reason 2: a security manager is applied
否则,Java确实有一位安全主管。 在这种情况下,这一理由不适用。
一位安保主管是确定申请的安全政策的对象。 如果你有一位安全主管,如果你是问题的根源,那么你就应当检查一下,它是否允许你向已解决的东道方(如果有的话)开一个记号。 为此,首先使用<代码>slookup 192.168.2.139<>/code>,并核实是否解决了东道国名。 如果东道国名称得不到解决,那么你的问题是“Reason 1”造成的。 如果它确实向东道国表示决心,例如<密码> myhostname,那么就会尝试:
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkConnect("myhostname", -1);
}
如果checkConnect(
接着,安全管理公司积极开展活动,并造成问题。 因此,你可以研究你如何能够没收你的安全。 管理者解决该问题。