俊星的BLOG

          WINDOWS和LINUX平臺獲取MAC地址

          Windows平臺:

          主要是通過執行“ipconfig /all”命令實現:
              public String getMyMACAddress() {
                  String macAddr 
          = "";
                  
          try {
                      Process p 
          = Runtime.getRuntime().exec("ipconfig /all");
                      BufferedReader reader 
          = new BufferedReader(new InputStreamReader(p.getInputStream()));
                      String line 
          = null;
                      
          while ((line = reader.readLine()) != null{
                          
          if (line.indexOf("Physical Address"> 0{
                              macAddr 
          = line.substring(line.indexOf(":"+ 1, line.length()).trim();
                              
          break;
                          }

                      }

                  }
           catch (IOException e) {
                      e.printStackTrace();
                  }

                  
          return macAddr;
              }

          Linux下的方式為:

          posted on 2009-06-03 20:39 俊星 閱讀(344) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 鹤山市| 阜平县| 丁青县| 昂仁县| 玉田县| 越西县| 胶南市| 甘德县| 海晏县| 仙游县| 宁都县| 那坡县| 临高县| 普格县| 巫山县| 涪陵区| 巩义市| 黑龙江省| 巨鹿县| 阿图什市| 余庆县| 遂平县| 廊坊市| 陆良县| 白山市| 靖远县| 永仁县| 望江县| 德昌县| 报价| 平原县| 哈密市| 河间市| 沛县| 宜昌市| 巧家县| 镇康县| 措美县| 中西区| 宝鸡市| 自贡市|