Sounds funny, but how can I get an external IP address from a client?
I tried several things but did not work for me.
in the first place I tried
request.getRemoteAddr()
and I get the result as: 0: 0: 0: 0: 0: 0: 0: 1
in second place I tried
InetAddress ip = InetAddress.getLocalHost(); ip.getHostAddress());
and I get the result as: 127.0.0.1
in third place I tried
URL whatismyip = new URL("http://checkip.dyndns.org:8245/"); BufferedReader inIP = new BufferedReader(new InputStreamReader(whatismyip.openStream())); String IPStrOld = inIP.readLine(); //IP as a String String IPStrNewest = IPStrOld.replace("<html><head><title>Current IP Check</title></head><body>Current IP Address: ", ""); String IPStr = IPStrNewest.replace("</body></html>", "");
but I only get the external IP address of the server
and for last place
URL whatismyip = new URL("http://automation.whatismyip.com/n09230945.asp"); BufferedReader inIP = new BufferedReader(new InputStreamReader(whatismyip.openStream())); String ip = inIP.readLine();
This is the same, I only get the external IP address of the server
So what is the deal?
source share