Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface ni = networkInterfaces.nextElement(); // up and running only if(!ni.isUp()) continue; byte[] hardwareAddress = ni.getHardwareAddress(); if (hardwareAddress != null) { String[] hexadecimalFormat = new String[hardwareAddress.length]; for (int i = 0; i < hardwareAddress.length; i++) hexadecimalFormat[i] = String.format("%02X", hardwareAddress[i]); String mac = String.join("-", hexadecimalFormat); System.out.println(mac); } }