Den*_*ees 6 java external ip-address
听起来很有趣,但我如何从客户端获取外部IP地址?
我尝试了一些东西,但对我没用.
首先,我试过
request.getRemoteAddr()
Run Code Online (Sandbox Code Playgroud)
我得到的结果为:0:0:0:0:0:0:0:1
在第二位,我试过
InetAddress ip = InetAddress.getLocalHost();
ip.getHostAddress());
Run Code Online (Sandbox Code Playgroud)
我得到的结果是:127.0.0.1
在第三位我试过了
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>", "");
Run Code Online (Sandbox Code Playgroud)
但我只获得服务器的外部IP
并为最后一个地方
URL whatismyip = new URL("http://automation.whatismyip.com/n09230945.asp");
BufferedReader inIP = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
String ip = inIP.readLine();
Run Code Online (Sandbox Code Playgroud)
这是一样的,我只得到服务器的外部IP
那么,这笔交易是什么?
归档时间: |
|
查看次数: |
5659 次 |
最近记录: |