Discussion Locked

ip of the client machine

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hi,
I'd like to write a servlet that would find out the ip address of the machine where it is being run.
can the same program find out the ip address of the client machine if it is hosted on the internet
please help.

5 replies

by jay eckles

See ServletRequest.getRemoteAddr() in the J2EE API specs. You can use it like this:

//(assuming HttpServletRequest request is defined)
String clientIP = request.getRemoteAddr() ;

Good luck.

Jay Eckles

by techrep

Hi. You might want to try the code below. It seems to detect internet ip if my machine is connected directly to the internet.

InetAddress localHost = InetAddress.getLocalHost();
String userhost = localHost.getHostAddress();

This discussion is closed to new replies.