Share this page 

Get the client IP address (deprecated)Tag(s): DEPRECATED


With modern java plugin installation, only "127.0.0.1" is displayed.

The only reliable way is to get this information from the server-side.

import java.net.*;
import java.io.*;
import java.applet.*;

public class GetClientIP extends Applet {
  public void init() {
    try {
     InetAddress thisIp =
        InetAddress.getLocalHost();
     System.out.println("IP:"+thisIp.getHostAddress());
     }
    catch(Exception e) {
     e.printStackTrace();
     }
    }
}

<HTML><HEAD></HEAD><BODY>
<APPLET CODE="GetClientIP.class"  
      HEIGHT=10 WIDTH=10>
 </APPLET>
 Check JAVA console for output
</BODY></HTML>
Try it here

NOTE: Netscape returns the IP address with the default security settings so it's not problem. With IE5, you must go to the security TAB, Internet, Java Custom, Edit and select "Allow access to all IP address".

Using a Servlet, this can be done with :

public void service(HttpServletRequest req, HttpServletResponse res) 
 throws IOException {
   String IP = req.getRemoteAddr();
  }