0

我想检查一个域是否存在,所以这是我的代码:

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我会收到响应,因为该域确实存在并托管了一个网站。

原因是什么?

谢谢

4

1 回答 1

0
InetAddress.getByName("www.ouestfrance-ecole.com")

工作正常(注意www子域)。这是ouestfrance-ecole.com不起作用的(也在我的浏览器中)。

于 2013-02-09T20:32:58.183 回答