简体   繁体   English

关于按名称获取IP地址

[英]About getting IP address by name

I would like to verify one thing about InetAddress.getByName(String) . 我想验证有关InetAddress.getByName(String)的一件事。

For example, there is an app sending request to its server named www.coolapp.com , I can get the IP address of this server by: 例如,有一个应用程序向其服务器发送请求,该服务器名为www.coolapp.com ,我可以通过以下方式获取该服务器的IP地址:

String serverIp = InetAddress.getByName("www.coolapp.com");

But if the app is designed to connect to different server geographically, does this function return the corresponding IP of the server the app is connecting to though the host name is the same "www.coolapp.com"? 但是,如果该应用程序设计为可在地理位置上连接到其他服务器,那么该功能是否返回与主机名相同的“ www.coolapp.com”相同的应用程序所连接服务器的IP?

For example, I am using the app in Europe, it connects to server in Germany, server host name is "www.coolapp.com" IP is 182.12.12.12. 例如,我在欧洲使用该应用程序,它连接到德国的服务器,服务器主机名是“ www.coolapp.com”,IP是182.12.12.12。 Then, if I travel to Japan, the app is connecting to "www.coolapp.com" IP is 123.13.13.13 Will the API return the corresponding IP based on the geo-location? 然后,如果我去日本旅行,该应用程序将连接到“ www.coolapp.com”。IP为123.13.13.13 API是否会根据地理位置返回相应的IP?

InetAddress.getByName() performs a DNS query, so DNS rules apply. InetAddress.getByName()执行DNS查询,因此适用DNS规则。

In DNS, you can get different IPs in different geographical locations. 在DNS中,您可以在不同的地理位置获得不同的IP。 However, DNS also allows more IPs to be defined per one DNS name ( link ). 但是,DNS还允许每个一个DNS名称链接定义更多IP In such case most DNS resolvers alternate between the addresses, so even in one goegraphical location you might get different IPs on two consecutive queries. 在这种情况下,大多数DNS解析器在地址之间交替,因此即使在一个象形位置,您也可能在两个连续的查询中获得不同的IP。 That might lead to you not getting the same IP you've connected to. 这可能导致您无法获得已连接到的IP。

Note that this might be subject to any caching on the way or on your computer. 请注意,这可能会受到途中或计算机上任何缓存的影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM