java 取得mac地址

okone96發表於2007-10-08

雖然不是什麼深奧東西,但我覺得給了我們一個取得資訊操作資訊的思路。

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;
}

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/750220/viewspace-975141/,如需轉載,請註明出處,否則將追究法律責任。

相關文章