HI TO ALL

import java.applet.*;
 import java.io.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.net.*;
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.net.UnknownHostException;
 




public class sid_fari extends Applet implements ActionListener 
 

{
   String msg,msgs,msgss;
   Button loads = new Button("clik me");
   
public void init(){

    add(loads);
    
    loads.addActionListener(this);


}

 public void paint(Graphics g)
   {
    

     g.drawString(msgs,10,40);
     g.drawString(msg,20,60);
       
       
        
        
    }

public void actionPerformed(ActionEvent evt) 
{

 
 InetAddress ip;
	try { 

		ip = InetAddress.getLocalHost();
               
                
		msgs="Current IP address : " + ip.getHostAddress();
               
                
                
		NetworkInterface network = NetworkInterface.getByInetAddress(ip);
                
		byte[] mac =network.getHardwareAddress();
            
                StringBuilder sb = new StringBuilder();
		for (int i = 0; i < mac.length; i++) {
			sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
                
                 msg="MAC ADDress" +sb.toString();
                 repaint();

		}
                
		
	} catch (UnknownHostException e) {

		e.printStackTrace();

	} catch (SocketException e){

		e.printStackTrace();

	}





}


  
}

This code works fine, in normal java.I created one applet program, which will give me the ipaddress.Instead of giving, local machine's ipAddress, it is giving Localhost ip.

For eg, my ipAddress is 10.1.85.26.

But is giving me as, 127.0.0.1

and it also not show me the mac number

WHAT SHOULD I DO.

The normal java program and an applet have different privileges. The security manager forbids applet's getLocalHost() to return anything but a loopback address.

thanxxxx so you mean to say its not possible through applet because of its limitations?

This article has been dead for over six months. Start a new discussion instead.