Full width home advertisement

Electronics Hub

Internet of Networks

Post Page Advertisement [Top]

Q. Write a Java program in order to check the MAC Address of your system.


Ans. 

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

public class macaddress 
{
public static void main(String[] args)  
 

  InetAddress ip;
  try {
   ip = InetAddress.getLocalHost();
   System.out.println("IP address : " + ip.getHostAddress());
   NetworkInterface network = NetworkInterface.getByInetAddress(ip);
   byte[] macaddress = network.getHardwareAddress();
   System.out.print("MAC address : ");
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < macaddress.length; i++)
  {
    sb.append(String.format("%02X%s", macaddress [i], (i < macaddress.length - 1) ? "-" : ""));
   }
   System.out.println(sb.toString());
  }
   catch (Exception e)
  {
   e.printStackTrace();
  }
 } 
}

Output: 

javac macaddress.java (//enter)
java macaddress (//enter)

IP address : 192.168.1.108 
MAC address : 80-88-E2-02-C0-2F


mac address, mac foundation
Free picture downloaded from unsplash.com
 

6 comments:

  1. Very useful info to know about MAC Address.

    Click here to read an interesting articleCan you live alone?

    ReplyDelete
  2. good. keep writing regularly ..... visit this site for marketing https://www.mydawn.top/2019/03/product-marketing.html

    ReplyDelete
  3. Your article about What is the MAC address of your system? is very helpful and informative. After reading we tried to note this following tips. So we are waiting for https://www.cybjurnal.com/

    ReplyDelete

Bottom Ad [Post Page]

| Designed by Sriparna Sarkar