我想检查一个域是否存在,所以这是我的代码:
try {
InetAddress inetAddress = InetAddress.getByName("ouestfrance-ecole.com");
System.out.println(inetAddress.getHostName());
System.out.println(inetAddress.getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
回应是:
java.net.UnknownHostException: ouestfrance-ecole.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1202)
at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
at java.net.InetAddress.getAllByName(InetAddress.java:1083)
at java.net.InetAddress.getAllByName(InetAddress.java:1019)
at java.net.InetAddress.getByName(InetAddress.java:969)
at MainApp.main(MainApp.java:18)
但是,如果我将 ouestfrance-ecole.com 放在浏览器中或执行,host ouestfrance-ecole.com
我会收到响应,因为该域确实存在并托管了一个网站。
原因是什么?
谢谢