我正在尝试写代码,如果我给它一个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是谷歌的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
有人能帮我弄清楚这件事吗?
发布于 2014-06-03 14:52:46
de-in-f103.1e100.net重定向到谷歌。
我猜74.125.24.105实际上导致了de-in-f103.1e100.net,然后再重定向到谷歌。在第一个例子中,您创建了一个指向具有相同ip的InetAddress的google.com。您可以通过跟踪重定向( windows命令行上的tracert)到达谷歌。
发布于 2014-06-03 15:28:43
通过阅读和做更多的调查,我终于能够回答这个问题。如果我将IP地址和域名添加到/etc/hosts文件并再次运行该类,它将生成插入到/etc/hosts文件中的域名,而不是原始响应。
https://stackoverflow.com/questions/24018308
复制相似问题