Java 5中的标准方法是启动一个本机进程来运行ipconfig或ifconfig解析OutputStream以获得您的答案。
例如:
private String getMacAddress() throws IOException { String command = “ipconfig /all”; Process pid = Runtime.getRuntime().exec(command); BufferedReader in = new BufferedReader(new InputStreamReader(pid.getInputStream())); Pattern p = Pattern.compile(”.*Physical Address.*: (.*)”); while (true) { String line = in.readLine(); if (line == null) break; Matcher m = p.matcher(line); if (m.matches()) { return m.group(1); } }}


