用java读MAC地址(原创)
利用JAVA来读取本机MAC地址:代码如下import *;
/*
* @Author Zengqingcong
* 2008-07-15
*/
public class ReadMacAddress {
public String getPhysicAddress() {
String physicalAddress = "";
String line = "";
try {
Process process = Runtime.getRuntime().exec("cmd /c ipconfig /all");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
while ((line = bufferedReader.readLine()) != null) {
if (line.indexOf("Physical Address. . . . . . . . . :") != -1) {
if (line.indexOf(":") != -1) {
physicalAddress = line.substring(line.indexOf(":") + 2);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return physicalAddress;
}
public static void main(String[] args) {
System.out.println("Your MacAddress is:\t"+new ReadMacAddress().getPhysicAddress());//My MacAddress is:00-16-E6-DA-AC-68
}
}