您的位置:首页 > 其它

获取Mac地址

2014-05-07 00:12 134 查看
/**

* 获取Mac地址

* @return

*/

public static String getMacAddress()

{

String mac = "";

String line = "";

String os = System.getProperty("os.name");

if (os != null && os.startsWith("Windows"))

{

try

{

String command = "cmd.exe /c ipconfig /all";

Process p = Runtime.getRuntime().exec(command);

BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));

while((line = br.readLine()) != null)

{

if (line.indexOf("Physical Address") > 0)

{

int index = line.indexOf(":") + 2;

mac = line.substring(index);

break;

}

}

br.close();

} catch (IOException e) {}

}

return mac;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: