小丑

泉涸,鱼相处于陆。相呴以湿,相濡以沫,不若相忘于一生!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

通过调用dos命令实现获取MAC地址

Posted on 2006-04-17 12:36  小丑  阅读(2701)  评论(0)    收藏  举报
public class Test {
    public static void main(String[] args) {
        try {
            Process process = Runtime.getRuntime().exec("ipconfig /all");
            InputStreamReader ir = new InputStreamReader(process
                    .getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
            String line;
            while ((line = input.readLine()) != null)
                if (line.indexOf("Physical Address") > 0) {
                    String MACAddr = line.substring(line.indexOf("-") - 2);
                    System.out.println("MAC address = [" + MACAddr + "]");
                }
        } catch (java.io.IOException e) {
            System.err.println("IOException " + e.getMessage());
        }
    }
}