java 取得mac地址
作者: okone96(http://okone96.itpub.net)发表于: 2007.10.08 18:57
分类: java技巧程序
出处: http://okone96.itpub.net/post/9033/403404
---------------------------------------------------------------
虽然不是什么深奥东西,但我觉得给了我们一个取得信息操作信息的思路。
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;
}



