What is the MAC address of your system?

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

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

public class mac
{
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[] mac = network.getHardwareAddress();
   System.out.print("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) ? "-" : ""));
   }
   System.out.println(sb.toString());
  }
   catch (Exception e)
  {
   e.printStackTrace();
  }
 }
}

Output:

javac mac.java (//enter)
java mac (//enter)

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



Comments

Popular posts from this blog

Harga Asuransi Mobil Online - Kiat dan Trik Penghematan Uang

Jenis Asuransi Tambahan

5 Cara Cepat untuk Mengurangi Premi Asuransi Mobil Anda