我正在尝试编写代码,如果我给它提供IP地址,它将返回一个域名。到目前为止,这是我所做的;
String destination = "173.194.24.144";
InetAddress address = InetAddress.getByName(destination);
String resolvedHost = address.getHostName();
System.out.println("Translated " + destination + " to host name " + resolvedHost);
我得到的是 Translated 173.194.24.144 to host name 173.194.24.144
我知道这173.194.24.144
是Google的IP地址。但是有了这个,我尝试了一个小实验,并对这种情况做了一些逆向工程。我试过了
InetAddress addr = InetAddress.getByName("www.google.com");
System.out.println("Host Name " + addr.getHostName());
System.out.println("Host Address " + addr.getHostAddress());
System.out.println("--------------------------------------------");
byte [] add = new byte[]{74, 125, 24, (byte) 105};
InetAddress ip = InetAddress.getByAddress(add);
System.out.println("Host Name " + ip.getHostName());
System.out.println("Host Address " + ip.getHostAddress());
我在响应中获得的IP被用在字节数组中,但是我得到的完整结果是:
Host Name www.google.com
Host Address 74.125.24.105
--------------------------------------------
Host Name de-in-f103.1e100.net
Host Address 74.125.24.105
但这让我更加困惑,de-in-f103.1e100.net
而不是www.google.com
谁能为我阐明一下?
de-in-f103.1e100.net
重定向到Google。
我猜这74.125.24.105
实际上导致de-in-f103.1e100.net
,然后重定向到Google。在第一个中,您使用相同的ip创建了一个InetAddress
指向google.com
。您可以通过跟踪重定向tracert
进入Windows (在Windows命令行上)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句