Get Network Card MAC Address in Java
March 9, 2010
This code will get the MAC address from a network card, using Java
public class MacAddressTest { public static void main(String[] args) throws Exception { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface nif = interfaces.nextElement(); byte[] lBytes = nif.getHardwareAddress(); StringBuffer lStringBuffer = new StringBuffer(); if (lBytes != null) { for (byte b : lBytes) { lStringBuffer.append(String.format("%1$02X ", new Byte(b))); } } System.out.println(lStringBuffer); } } }