java获取本机mac地址

作者: ldsea 分类: 程序生活 发布时间: 2008-09-10 10:35

[code]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;
}[/code]

发表回复

您的电子邮箱地址不会被公开。