共计 379 个字符,预计需要花费 1 分钟才能阅读完成。
InetAddress ip = InetAddress.getLocalHost();
System.out.println("IP:"+ip);
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.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) ? "-" : ""));
}
String hostMac=sb.toString();
System.out.println("Current MAC address : "+hostMac);
正文完