【问题标题】:need to obtain the public IP of the user but getting the IP of the server where the app is deployed [duplicate]需要获取用户的公共IP,但获取部署应用程序的服务器的IP [重复]
【发布时间】:2012-09-03 15:11:00
【问题描述】:

可能重复:
Finding out your website visitor IP address in Java

我想为我的网站维护日志。为此,我需要存储访问者的公共 IP。我怎样才能做到这一点 ?直到知道我这就是我一直在做的事情:

         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 的东西。

我怎样才能得到这个IP?哪个是访问网站的用户的公共 IP。

【问题讨论】:

    标签: java ip


    【解决方案1】:

    每个Request 到您的Web 应用程序,客户端的IP 也被发送。所以你需要做的就是让Filter 超过Requests。获取和存储您喜欢的任何信息。

    【讨论】:

      猜你喜欢
      • 2011-07-16
      • 2020-07-24
      • 2014-12-16
      • 2011-09-11
      • 1970-01-01
      • 2020-08-05
      • 2014-05-31
      • 2021-03-25
      • 1970-01-01
      相关资源
      最近更新 更多