/*获取本机mac地址*/
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)
{
System.out.println(line);
if (line.indexOf("Physical Address") > 0||line.indexOf("物理地址") > 0)
{
int index = line.indexOf(":") + 2;
mac = line.substring(index);
break;
}
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
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)
{
System.out.println(line);
if (line.indexOf("Physical Address") > 0||line.indexOf("物理地址") > 0)
{
int index = line.indexOf(":") + 2;
mac = line.substring(index);
break;
}
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}