?Spring Boot???MAC????????????:
- ???????:
io.netty netty-runtime 4.1.65.Final
- ??????????MAC??:
import io.netty.channel.socket.nio.NioDatagramChannel; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.UnknownHostException; public class MacAddressUtils { public static String getMacAddress() { try { NetworkInterface network = NetworkInterface.getByInetAddress(InetAddress.getLocalHost()); byte[] mac = network.getHardwareAddress(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) { sb.append(String.format("X%s", mac[i], (i < mac.length - 1) ? "-" : "")); } return sb.toString(); } catch (SocketException | UnknownHostException e) { e.printStackTrace(); } return null; } }
- ?????MAC???????????????:
String macAddress = MacAddressUtils.getMacAddress(); System.out.println(macAddress);
???,?????????????MAC???????????????MAC??,??????????