0

I have a web-server that is behind a router. One of the servlets on that server relies on the IP address of the user, however, i often get the IP of my router (i.e. 192.168.1.1) instead of the real IP.

How can i fix that?

Ibolit
  • 9,218
  • 7
  • 52
  • 96
  • Hi, I have the same problem. Did you find solution? – peter Feb 18 '15 at 01:58
  • No, I had to find a different way out. Unfortunately, I don't remember what exactly I did. Basically, you can identify the user in other ways, like getting their session id, etc. – Ibolit Feb 19 '15 at 07:34

3 Answers3

4

It sounds like your "router" is actually acting like a reverse proxy.

It is unlikely that you will be able to solve this in Java ... or even on your server machine. It sounds like a router configuration problem. You might be better off asking for help on "superuser" or "serverfault".

One thing to bear in mind is that identifying clients by IP address is always a bit dodgy. Even once you've sorted out the current problem, the real client IP address may not be available for various reasons:

  • The client's IP may be NATed.

  • The client may be talking to your webserver via a series of HTTP proxies.

  • The client may be spoofing its IP address.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

Grab your global IP from http://www.whatismyip.com/ , I think you might also need to configure port forwarding on router of user that is having servlet.

Harmeet Singh
  • 2,555
  • 18
  • 21
  • I know my global ip. Basically, i have two computers in my lan. One of them is running a web-server using tomcat+servlets. Another (say, ...32) makes a request to it. I need to be able to tell that IP from my servlet. Port forwarding also set up – Ibolit Aug 28 '12 at 05:20
  • If the request is local, then there is no need of port forwarding, can you please share that servlet code. – Harmeet Singh Aug 28 '12 at 05:24
0

I would suggest that access http://wwww.whatismyip.com to get you IP adddress in case you have not tried that way.You will more idea from this link.

Getting the 'external' IP address in Java

Community
  • 1
  • 1
UVM
  • 9,776
  • 6
  • 41
  • 66