java获取本机mac地址

try
{
  Process process = Runtime.getRuntime().exec("ipconfig /all");
  InputStreamReader ir = new InputStreamReader(process .getInputStream());
  LineNumberReader input = new LineNumberReader(ir);
  String line;
  while ((line = input.readLine()) != null)
    if (line.indexOf("Physical Address") > 0)
    {
      String MACAddr = line.substring(line.indexOf("-") - 2);
      System.out.println("MAC address = [" + MACAddr + "]");
    }
}
catch (java.io.IOException e)
{
  System.err.println("IOException " + e.getMessage());
}

 

你可能感兴趣的:(java)