且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Servlet 中获取真实的客户端 IP

更新时间:2022-06-22 23:12:46

我想你的问题是你在本地网络的某个地方运行服务器,所以你在那个网络中获得了你的 IP.但是,当您尝试使用发现您的 IP 地址的在线服务时,您的 IP 是您的服务提供商路由器的 IP 或类似的东西.使用 request.getRemoteAddr() 是正确的.这就是这些服务所做的,他们没有其他设施.

I suppose that your problem is that you are running server somewhere in local network, so you get your IP in that network. However when you are trying to use online service that discovers your IP address your IP is the IP of your service provider's router or something like this. Using request.getRemoteAddr() is correct. This is what such services do and they do not have other facilities.