Getting wrong ip address in java


This question already has an answer here:


If that IP address ( is the (or a) firewall, then it is the right IP address. Your server-side code is reporting the "client" IP address that it sees, and it can't do any better.

In general, there are a couple of possible explanations as to what is going on:

  • The firewall could be running an HTTP proxy, and your client machine could be configured send all HTTP requests through the proxy. If the client is capable of talking directly to the server, then you may be able to modify the client's proxy settings to treat the server as an exception.

  • The firewall could be providing a NAT service that is isolating one part of you networks from another part (for example). If this is the issue, then you will need your network administrators' help.

  • It is common (and often "good practice") to run a Tomcat server on (say) port 8080, and put it behind a reverse proxy on port 80.

In your case, the first explanation is most likely.

@andrucz suggests using the Tomcat Remote IP Filter. That will work in some circumstances, but not all, and it is using information that can easily be "spoofed"

The bottom line is that it is common for a webserver to not be able to see the real IP addresses of clients. So it is inadvisable to implement your services to depend on this.

You can use Tomcat Remote IP Filter:

Maybe you will need network administrators' help to configure firewall to include "X-Forwarded-For" header.

Need Your Help

Node.js: setInterval function doesn't work

javascript node.js setinterval

I'm emulating data using the Mockaroo API. Then I want to post them every second in my database. So when I test the post method using Postman it works well, but when I try to use setInterval() it d...