如题所述
来走一个
InetAddress inetAddress = InetAddress.getLocalHost();
//获取网卡,获取地址
byte[] mac = NetworkInterface.getByInetAddress(inetAddress).getHardwareAddress();
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < mac.length; i++){
if (i != 0){
sb.append("-");
}
//字节转换为整数
int temp = mac[i] & 0xff;
String str = Integer.toHexString(temp);
if (str.length() == 1){
sb.append("0" + str);
}else{
sb.append(str);
}
}
System.out.println("本机MAC地址:" + sb.toString().toUpperCase());
}
输出:
本机MAC地址:B8-88-E3-FA-03-39
温馨提示:答案为网友推荐,仅供参考