Chinaunix首页 | 论坛 | 博客
  • 博客访问: 356900
  • 博文数量: 132
  • 博客积分: 3066
  • 博客等级: 中校
  • 技术积分: 781
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-14 16:19
文章分类

全部博文(132)

文章存档

2012年(1)

2010年(50)

2009年(81)

我的朋友

分类: Java

2010-06-10 12:12:10

获取网卡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;
        }
    }
阅读(1111) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~