Java,J2EE,Weblogic,Oracle

java项目随笔
随笔 - 90, 文章 - 6, 评论 - 61, 引用 - 0
数据加载中……

java执行命令,得到Mac地址

public static void main(String[] args) {
  String os = System.getProperty("os.name");

  System.out.println("操作系统:"+os);
  
  String address = "";
  if (os != null && os.startsWith("Windows")) {
            try {
                String command = "cmd.exe /c ipconfig /all";
                Process p = Runtime.getRuntime().exec(command);
                BufferedReader br =
                        new BufferedReader(
                                new InputStreamReader(p.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    if (line.indexOf("Physical Address") > 0) {
                        int index = line.indexOf(":");
                        index += 2;
                        address = line.substring(index);
                        break;
                    }
                }
                br.close();              
            } catch (Exception e) {}
        }
  
  System.out.println("网卡Mac地址:"+address);

 }

posted on 2007-09-06 10:41 龚椿深 阅读(585) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: