from:http://ywh5.bokee.com/viewdiary.13113717.html
private String getPhysicalAddress() {
String cmd = "cmd.exe /c ipconfig/all";
String strRs="";
String result="";
strRs=executeSysCMD(cmd);
result = parseCmd(strRs);
return result;
}
private String executeSysCMD(String shellCommand) {
try {
Start(shellCommand);
StringBuffer sb = new StringBuffer();
DataInputStream in = new DataInputStream(p.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
do {
line = reader.readLine();
if (line == null) {
break;
}
else {
sb.append(line);
}
}
while (true);
reader.close();
return sb.toString();
}
catch (Exception e) {
//error
return null;
}
}
private String parseCmd(String s) {
String find = "Physical Address. . . . . . . . . :";
int findIndex = s.indexOf(find);
if (findIndex == -1)
return "not find";
else
return s.substring(findIndex + find.length() + 1,
findIndex + find.length() + 1 + _physicalLength);
}
你可以通過這個連結引用該篇文章:http://ywh5.bokee.com/tb.b?diaryId=13113717
看到這篇文章 轉貼一下!!晚上回來進行驗證正確性!!!