You can use the following example to get the client IP address in Applet. The process is not so straightforward, you have to get the current host and port from where Applet is loaded, and convert it to Socket object.

Socket socket = new Socket(getDocumentBase().getHost(), port);
ip = socket.getLocalAddress().getHostAddress();

Example to get IP address in Applet

package com.mkyong.applet;
 
import java.applet.*;
import java.awt.Graphics;
import java.io.IOException;
import java.net.Socket;
 
public class AppletExample extends Applet {
 
	String ip;
 
	public void init() {
 
	  try{
		int port;
 
		if(getDocumentBase().getPort()!=-1){
			port = getDocumentBase().getPort();
		}else{
			port = 80;
		}
 
	        Socket socket = new Socket(getDocumentBase().getHost(), port);
		ip = socket.getLocalAddress().getHostAddress();
 
            }catch(IOException io){
		System.out.println(io.getMessage());
	    }
	}
 
	public void paint( Graphics g ) {
 
	   StringBuffer sb = new StringBuffer()
   		.append(" IP address : ").append(ip);
 
	   g.drawString(sb.toString(), 0,100);
	}
 
}
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world\'s largest enterprise software company.
Publisher : Oracle Corporation