import java.net.InetAddress;import java.net.NetworkInterface;import java.net.SocketException;import java.net.UnknownHostException;public class LocalMac { public static void main(String[] args) throws UnknownHostException, SocketException { InetAddress ia = InetAddress.getLocalHost(); System.out.println(ia); System.out.println("本机mac地址:" + getLocalMac(ia)); } private static String getLocalMac(InetAddress ia) throws SocketException { byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress(); // System.out.println("mac数组长度:"+mac.length); StringBuffer sb = new StringBuffer(""); for(int i=0; i
输出:
DESKTOP-NDJUAVS/192.168.43.1本机mac地址:00-50-56-C0-00-08
参考地址: