java获取本机mac地址

关键代码如下: public static String getMac() throws IOException { String command=”ipconfig /all”; String mac=null; Process proc=Runtime.getRuntime().exec(command); BufferedReader reader=new BufferedReader(new InputStreamReader(proc.getInputStream())); String line=null; while((line=reader.readLine())!=null) { if(line.indexOf(“Physical Address”)!=-1) { mac=line.substring(line.indexOf(“Physical Address”)+36, line.length()); break; } } return mac; }

yava /
in categories tagged with