I'm connecting to a url with a httpurlconnection in java 1.6
The server I connect uses DNS round robin to share load between multiple servers.
How can I get the remote ip address that I have actually connected to?
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
//I then need something like this!
log(SUCCESS, "made connection to: " + urlConn.getRemoteIp());
URL url = new URL("http://yahoo.com");
String host = url.getHost();
InetAddress address = InetAddress.getByName(host);
String ip = address.getHostAddress();
Not directly, but since the JVM is caching DNS lookups, you can use InetAddress.getByName(serverName) to find the actual IP address being used unless you've set the system property "networkaddress.cache.ttl" to disable the cache.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With