需要获取用户的公共IP,但获取部署应用程序的服务器的IP [英] need to obtain the public IP of the user but getting the IP of the server where the app is deployed
问题描述
可能重复:
用Java查找您的网站访问者IP地址
我想维护我网站的日志。为此,我需要存储访客的公共IP。我怎样才能做到这一点 ?直到知道我这就是我一直在做的事情:
I want to maintain logs for my website. For that I need to store the public IP of the visitor. How can I do that ? Till know I this was what I have been doing :
URL ip = new URL("http://api.externalip.net/hostname/");
BufferedReader br = new BufferedReader(new InputStreamReader(ip.openStream()));
String publicIP = br.readLine();
但这会返回服务器的IP,我想这是托管页面的位置。例如,我总是得到IP: 76.xxxxxxxx
但是当我从查看时 whatismyip
我有类似 106.xxxxxxx
的内容。
but this returns me the IP of the server , I guess where the page is hosted. For example I always get the IP as : 76.xxxxxxxx
but when I check from whatismyip
I have something like 106.xxxxxxx
.
我如何获得此IP?哪个是访问该网站的用户的公共IP。
How can I get this IP ? Which is the public IP of the user from which it visits the website.
推荐答案
每个请求到您的Web应用程序,客户端的IP也被发送。所以你需要做的就是过滤 请
。获取并存储您喜欢的任何信息。
With every Request to your web application, client's IP is sent too. So all you need to do is to have Filter over Requests
. Gain and store any information you like.
这篇关于需要获取用户的公共IP,但获取部署应用程序的服务器的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!