public static String getMac() { ??? try { ??????? List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces()); ??????? for (NetworkInterface nif : all) { ??????????? if (!"wlan0".equalsIgnoreCase(nif.getName())) { ??????????????? continue; ??????????? } ??????????? byte[] macBytes = nif.getHardwareAddress(); ??????????? if (macBytes == null || macBytes.length == 0) { ??????????????? continue; ??????????? } ??????????? StringBuilder result = new StringBuilder(); ??????????? for (byte b : macBytes) { ??????????????? result.append(String.format("%02X", b)); ??????????? } ??????????? return result.toString().toUpperCase(); ??????? } ??? } catch (Exception x) { ??????? x.printStackTrace(); ??? } ??? return ""; }
亲测有效
?
?
|