NetworkInterface: getHardwareAddress() throws SocketException

 
import java.net.InetAddress;
import java.net.NetworkInterface;

public class Main {
  public static void main(String[] args) throws Exception {
    InetAddress address = InetAddress.getLocalHost();

    NetworkInterface ni = NetworkInterface.getByInetAddress(address);
    byte[] mac = ni.getHardwareAddress();

    for (int i = 0; i < mac.length; i++) {
      System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
    }
  }
}
  
Home 
  Java Book 
    Networking  

NetworkInterface:
  1. NetworkInterface
  2. NetworkInterface: getDisplayName()
  3. NetworkInterface: getHardwareAddress()
  4. NetworkInterface: getHardwareAddress() throws SocketException
  5. NetworkInterface: getInetAddresses()
  6. NetworkInterface: getName()