Skip to content

Instantly share code, notes, and snippets.

@timendum
Created July 27, 2011 10:06
Show Gist options
  • Save timendum/1109057 to your computer and use it in GitHub Desktop.
Save timendum/1109057 to your computer and use it in GitHub Desktop.
Get MAC Address in Java
public static void main(String[] args) throws SocketException {
Enumeration<NetworkInterface> networks = NetworkInterface.getNetworkInterfaces();
NetworkInterface inter;
while (networks.hasMoreElements()) {
inter = networks.nextElement();
byte[] mac = inter.getHardwareAddress();
if (mac != null) {
for (int i = 0; i < mac.length; i++) {
System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
}
System.out.println("");
}
}
}
@Urunov
Copy link

Urunov commented Aug 23, 2022

It is working with me.
3 categories are included :
VPN
WSDL
Ethernet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment