问题描述
- Java中如何获取用户mac地址?
-
在Java项目中如何用代码获取用户MAC地址,我用的是w7系统
解决方案
http://blog.163.com/09zzy@126/blog/static/71197665201001504753750/
解决方案二:
public static String getWindowsMACAddress() {
String mac = null;
BufferedReader bufferedReader = null;
Process process = null;
try {
/**
* windows下的命令,显示信息中包含有mac地址信息
*/
process = Runtime.getRuntime().exec("ipconfig /all");
bufferedReader = new BufferedReader(new InputStreamReader(process
.getInputStream()));
String line = null;
int index = -1;
while ((line = bufferedReader.readLine()) != null) {
/**
* 寻找标示字符串[physical address]
*/
index = line.toLowerCase().indexOf("物理地址"); //注意用ipconfig -all看一下字符,中英文是不一样的
if (index != -1) {
index = line.indexOf(":");
if (index != -1) {
/**
* 取出mac地址并去除2边空格
*/
mac = line.substring(index + 1).trim();
}
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if (bufferedReader != null) {
bufferedReader.close();
}
}catch (IOException e1) {
e1.printStackTrace();
}
bufferedReader = null;
process = null;
}
return mac;
}
解决方案三:
http://blog.csdn.net/yangjunjiezai/article/details/8229084
时间: 2025-01-19 13:36:39