For each request, a servlet has the ability to find out about the client machine and, for pages requiring authentication, about the actual user.
This information can be used for logging access data, associating information with individual users, or restricting access to certain clients.
Retrieving Information About the Client Machine
A servlet can use getRemoteAddr() and getRemoteHost() to retrieve the IP address and hostname of the client machine, respectively:
public String ServletRequest.getRemoteAddr()
public String ServletRequest.getRemoteHost()
Both values are returned as String objects. The information comes from the socket that connects the server to the client, so the remote address and hostname may be that of a proxy server. An example remote address might be "192.26.80. 118" while an example remote host might be "dist.engr. sgi.com". The IP address or remote hostname can be converted to a java.net.InetAddress object using InetAddress.getByName():