View Single Post
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Viewing An IP Address in Command Prompt

 
0
  #7
May 25th, 2005
Originally Posted by C++
thanx. one more question. is there a way to return the ip address to a java/c++ program?
This is how you can grab the client ip address:
  InetAddress thisIp =
        InetAddress.getLocalHost();
     System.out.println("IP:"+thisIp.getHostAddress());

Remember to include that in a try catch clause, as that code could potentially cause an exception.

Also, writting a simple servlet would be easier:

String IP = req.getRemoteAddr();
req is an HTTPServletRequest Object.
Reply With Quote