/**
* 获取本机mac地址
* @return
*/
public static String getMac() {
StringBuffer sb = new StringBuffer("");
try {
InetAddress ia = InetAddress.getLocalHost();
System.out.println(ia);
byte[] mac = NetworkInterface .getByInetAddress(ia).getHardwareAddress();
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.toUpperCase());
}else {
sb.append(str.toUpperCase());
}
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
}
return sb.toString();
}