getRemoteAddr, getRemoteHost and getRemotePort of ServletRequest returns details of the client calling the services. It can be the end client (request made directly from the client to server) or proxy (If there are proxy servers or NATting firewalls between your web server or servlet engine and the end users)
Being defeated is often a temporary condition. Giving up is what makes it permanent.
Joined: May 21, 2008
Thanks for reply Fuzail but i have tested all of them, they return IP address of either web server or proxy server. How can i get Client machine's information. In aspx, it is possible but i can not find it in java
But if the request is coming directly from client then it can return null. So you need to take care of this condition also
Another point is that there is no guarantee that the proxy server will pass that header for you. So, the fact that the header is null, doesn't necessarily mean that the IP returned by getRemoteAddr is the actual IP of the machine that made the original request. It could still be the IP of a proxy server.
There is no absolute way to know the IP of the originating machine from a web app.
request.getRemoteAddr() is the way. It appears your proxy changes the source IP. When some proxies do that they add the original IP in some custom http header. Use request.getHeaders() and print all of them to see if there isn't anything of interest. Like X-CLIENT-IP (made that one up, )
I have a question too.
How I can get the website ip that the http call came from. Let's say I have a jsonp call that calls a jsp file. How I can get the ip or url of the domain that this call came from and not the client/user information? Or is there any way to authenticate that the call came from a list of domains/ips in my database?
subject: How to get client's IP address, Domain using Java