【问题标题】:InetAddress keeps changing and i'm not getting the address i expected [closed]InetAddress 不断变化,我没有得到我期望的地址 [关闭]
【发布时间】:2019-08-27 09:25:26
【问题描述】:

这可能是一个与网络相关的问题,虽然我无法真正了解发生了什么。

InetAddress giriAddress = java.net.InetAddress.getByName("www.google.com");
String address = giriAddress.getHostAddress();
System.out.println(address);
//output
//74.125.24.147 as well as 216.58.210.228

我的预期:

  • 8.8.8.8

我得到了什么:

  • 74.125.24.147

  • 216.58.210.228

注意:

事实上,通过访问这两个地址,我正在查看谷歌的主页

我的问题:

为什么8.8.8.8 没有返回?为什么这两个地址相互循环?

【问题讨论】:

  • 你为什么期待8.8.8.8?此外,谷歌很有可能在多个服务器上使用负载平衡。
  • 我以为8.8.8.8IP后面的IP
  • 这既是“不清楚你在问什么”又是“离题”。
  • 为什么会这样呢?为什么跑题了?

标签: java networking


【解决方案1】:

8.8.8.8 是 Google 的 DNS 服务器 的 IP 地址。

您得到的是托管www.google.com网络服务器解析IP地址

来自InetAddress#getByName

Determines the IP address of a host, given the host's name.

所以它实际上会为您解析 DNS。

【讨论】:

猜你喜欢
  • 2020-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多