Tag: external

客户端的外部IP地址

听起来很有趣,但我如何从客户端获取外部IP地址? 我尝试了一些东西,但对我没用。 首先,我试过 request.getRemoteAddr() 我得到的结果为:0:0:0:0:0:0:0:1 在第二位,我试过 InetAddress ip = InetAddress.getLocalHost(); ip.getHostAddress()); 我得到的结果是: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(“Current IP CheckCurrent IP Address: “, “”); String IPStr = IPStrNewest.replace(“”, “”); 但我只获得服务器的外部IP 并为最后一个地方 URL whatismyip = new URL(“http://automation.whatismyip.com/n09230945.asp”); BufferedReader […]