我正在使用java 1.6中的httpurlconnection连接到一个url
我连接的服务器使用DNS循环调度在多个服务器之间共享负载。
如何获取我实际连接到的远程ip地址?
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
//I then need something like this!
log(SUCCESS, "made connection to: " + urlConn.getRemoteIp());发布于 2010-01-21 17:31:22
URL url = new URL("http://yahoo.com");
String host = url.getHost();
InetAddress address = InetAddress.getByName(host);
String ip = address.getHostAddress();发布于 2010-01-21 17:32:12
不是直接使用,但是因为JVM正在缓存DNS查找,所以您可以使用InetAddress.getByName(serverName)来查找实际使用的IP地址,除非您已经将系统属性"networkaddress.cache.ttl“设置为禁用缓存。
https://stackoverflow.com/questions/2108072
复制相似问题