java获取网卡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; 
        } 
    }
posted @ 2011-07-13 10:02  lostyue  阅读(845)  评论(0编辑  收藏  举报