Java获取网卡的mac地址(二)

2014-11-24 00:58:14 · 作者: · 浏览: 15
catch (Exception ex) {
System.out.println("windows 7方式未获取到网卡地址");
}
return sb.toString();
}


/**
* 获取MAC地址
*
* @param argc
* 运行参数.
* @throws Exception
*/
public static String getMACAddress() {
// windows
String mac = getWindowsMACAddress();
// windows7
if (isNull(mac)) {
mac = getWindows7MACAddress();
}
// unix
if (isNull(mac)) {
mac = getUnixMACAddress();
}


if (!isNull(mac)) {
mac = mac.replace("-", "");
}
else {
mac = "ABCDEFGHIJ";
}
return mac.toLowerCase();
}


public static boolean isNull(Object strData) {
if (strData == null || String.valueOf(strData).trim().equals("")) {
return true;
}
return false;
}


public static void main(String[] args) {
System.out.println(getWindows7MACAddress());
}


}