发新话题
移动帖子 加入精华 加入置顶 加入收藏 关注此帖

Runtime.exec()方式获取网卡的MAC地址





Runtime.exec()方式获取网卡的MAC地址

  /**
   * 获取网卡MAC地址
   */
  public static String getMacOnWindow() {
    try {
      String mac = null;
      Process process = Runtime.getRuntime().exec("ipconfig /all");
      BufferedReader buffer = new BufferedReader(new InputStreamReader(process.getInputStream()));
      for (String line = buffer.readLine(); line != null; line = buffer.readLine()) {
        int index = line.indexOf("Physical Address");
        if (index <= 0) {
          continue;
        }
        mac = line.substring(index + 36);
        break;
      }
      buffer.close();
      process.waitFor();
      return mac;
    } catch (Exception exception) {
      return null;
    }
  }
快乐渡过每一天,减肥坚持每一天



编辑 回复 快速回复 TOP


Re:Runtime.exec()方式获取网卡的MAC地址

相当于是执行了cmd->ipconfig命令吧
[img]http://tinyurl.com/5jrvqw[/img]
[img]http://tinyurl.com/6b5cxa[/img]
[img]http://tinyurl.com/5phqbo[/img]
编辑 回复 快速回复 TOP
发新话题