package com.lxh.test;
import java.io.*;
/*
* lxh
*/
public class Test {
public static void main(String[] args) throws Exception {
String line;
String physicalAddress = "read MAC error!";
try {
Process p=Runtime.getRuntime().exec("cmd.exe /c ipconfig /all");
//p.waitFor();
BufferedReader bd =new BufferedReader(new InputStreamReader (p.getInputStream()));
while((line=bd.readLine())!=null){
if(line.indexOf("Physical Address. . . . . . . . . :")!=-1){
if(line.indexOf(":")!=-1){
physicalAddress = line.substring(line.indexOf(":")+2);
break; //找到MAC,推出循环
}
}
}
p.waitFor();
System.out.println("信息:"+line+"/n");
System.out.println("本机的MAC地址是: "+ physicalAddress);
} catch (IOException e) {
e.printStackTrace();
}
}
}