/**
* 获取网卡MAC地址
*/
public static String getMacOnWindow() {
try {
String mac = null;
Process process = Runtime.getRuntime().exec("ipconfig /all");
BufferedReader buffer =
new BufferedReader(new InputStreamReader(process.getInputStream()));
for (String line = buffer.readLine(); line != null; line = buffer.readLine()) {
int index = line.indexOf("Physical Address");
if (index <= 0) {
continue;
}
mac = line.substring(index + 36);
break;
}
buffer.close();
process.waitFor();
return mac;
} catch (Exception exception) {
return null;
}
}
* 获取网卡MAC地址
*/
public static String getMacOnWindow() {
try {
String mac = null;
Process process = Runtime.getRuntime().exec("ipconfig /all");
BufferedReader buffer =
new BufferedReader(new InputStreamReader(process.getInputStream()));
for (String line = buffer.readLine(); line != null; line = buffer.readLine()) {
int index = line.indexOf("Physical Address");
if (index <= 0) {
continue;
}
mac = line.substring(index + 36);
break;
}
buffer.close();
process.waitFor();
return mac;
} catch (Exception exception) {
return null;
}
}
本文介绍了一种在Windows系统中通过Java程序获取本地网卡MAC地址的方法。该方法使用Runtime.getRuntime().exec()执行系统命令ipconfig /all来获取网络配置信息,并通过解析输出结果来提取出MAC地址。
977

被折叠的 条评论
为什么被折叠?



