首页 > 应用开发 > Java > java 取得mac地址
虽然不是什么深奥东西,但我觉得给了我们一个取得信息操作信息的思路。
public static String getMACAddress() {
String address = "";
String os = System.getProperty("os.name");
System.out.println(os);
if (os != null && os.startsWith("Windows")) {
try {
ProcessBuilder pb = new ProcessBuilder("ipconfig", "/all");
Process p = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
if (line.indexOf("Physical Address") != -1) {
int index = line.indexOf(":");
address = line.substring(index + 1);
break;
}
}
br.close();
return address.trim();
} catch (IOException e) {
}
}
return address;
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/750220/viewspace-975141/ ,如需转载,请注明出处,否则将追究法律责任。