Media Access Control address (MAC address) is a unique hexadecimal identifier assigned to a Network Interface Controller (NIC) to be used as a network address in communications within a network segment. This use is common in most IEEE 802 networking technologies, including Ethernet, Wi-Fi, and Bluetooth. Within the Open Systems Interconnection (OSI) network model, MAC addresses utilized in the medium access control protocol sublayer of the data link layer. As typically represented, MAC addresses are recognizable as six groups of two hexadecimal digits, separated by hyphens, colons, or without a separator.
MAC addresses are primarily assigned by device manufacturers and therefore often mentioned as the burned-in address, or as an Ethernet hardware address, hardware address, or physical address.

Example 1
Java
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
public class MACAddress {
void getMAC(InetAddress addr) throws SocketException
{
NetworkInterface iface
= NetworkInterface.getByInetAddress(addr);
byte [] mac = iface.getHardwareAddress();
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());
}
public static void main(String[] args) throws Exception
{
InetAddress addr = InetAddress.getLocalHost();
MACAddress obj = new MACAddress();
System.out.print( "MAC Address of the system : " );
obj.getMAC(addr);
}
}
|
Output

Example 2(When the device has more than one MAC address)
Java
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
public class MACAddress {
public static void main(String[] args) throws Exception
{
MACAddress obj = new MACAddress();
obj.getMAC();
}
void getMAC()
{
try {
Enumeration<NetworkInterface> networks
= NetworkInterface.getNetworkInterfaces();
while (networks.hasMoreElements()) {
NetworkInterface network
= networks.nextElement();
byte [] mac = network.getHardwareAddress();
if (mac != null ) {
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 ) ? "-"
: "" ));
}
System.out.println(sb.toString());
}
}
}
catch (SocketException e) {
e.printStackTrace();
}
}
}
|
Output
