hi to all
i made a code to find the mac number that runs on java and gives me output but when i implement it on applet and link the applet with html then applet links correctly but the logic to find mac number does not execute.....what should i do...here is my code

import java.net.*;

public class Main {

    public static void main(String[] args) {

 InetAddress ip;
	try {

		ip = InetAddress.getLocalHost();
		System.out.println("Current IP address : " + ip.getHostAddress());

		NetworkInterface network = NetworkInterface.getByInetAddress(ip);

		byte[] mac = network.getHardwareAddress();

		System.out.print("Current MAC address : ");

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < mac.length; i++) {
           sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));

	} catch (UnknownHostException e) {


	} catch (SocketException e){




what i can use instead of system.out.println

I don't think that you can use println in this case. You need something like this:

public void paint(Graphics g) {
        g.drawString("Hello world!", 50, 25);

thanks that works but the ip address i got is not correct in applet....why this happened

ip = InetAddress.getLocalHost();
		msgs="Current IP address : " + ip.getHostAddress();

i got output but not correct.....help me

try this :

 * To change this template, choose Tools | Templates
 * and open the template in the editor.
package javaapplication8;

import java.net.InetAddress;
import java.applet.*;
import java.awt.*;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class JavaApplication8 extends Applet{
      public void paint( Graphics g ) {
        try {
            InetAddress local = InetAddress.getLocalHost();         
        String myLocalIP = local.getHostAddress();
            //String ip = InetAddress.getLocalHost().toString();
        } catch (UnknownHostException ex) {
            Logger.getLogger(JavaApplication8.class.getName()).log(Level.SEVERE, null, ex);

If you don't see what you expect to see please provide us with more information about the error (error message etc etc). Using that, you are able to take your private IP (The IP that has been assigned to your PC by your router[dhcp]) not your public IP.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.