InetAddress.getLocalHost().getHostAddress();

解决方案 »

  1.   

    没用,这个只能获取IP地址,不是MAC地址
      

  2.   

    InetAddress.getLocalHost().getHostAddress();
      

  3.   

    没办法,
    现在很多的做法是调用本地的程序ipconfig(在windows下,在linux下就是调另外的命令),然后取得信息
    搜一下,论坛上有的
      

  4.   

    就是楼上所说的方法:
    private static String getMacOnWindow() {
            String s = "";
            try {
                String s1 = "ipconfig/all";
                Process process = Runtime.getRuntime().exec(s1);
                BufferedReader bufferedreader = new BufferedReader(
                        new InputStreamReader(process.getInputStream()));
                String nextLine;
                for (String line = bufferedreader.readLine(); line != null; line = nextLine) {
                    nextLine = bufferedreader.readLine();
                    if (line.indexOf("Physical Address") <= 0) {
                        continue;
                    }
                    int i = line.indexOf("Physical Address") + 36;
                    s = line.substring(i);
                    break;
                }            bufferedreader.close();
                process.waitFor();
            } catch (Exception exception) {
                s = "";
            }
            return s.trim();
        }