Reputation: 42582
I would like to verify one thing about 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:
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"?
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. 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?
Upvotes: 0
Views: 88
Reputation: 12440
InetAddress.getByName()
performs a DNS query, so DNS rules apply.
In DNS, you can get different IPs in different geographical locations. However, DNS also allows more IPs to be defined per one DNS name (link). 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. That might lead to you not getting the same IP you've connected to.
Note that this might be subject to any caching on the way or on your computer.
Upvotes: 1