俊星的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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 绥芬河市| 洛阳市| 邹城市| 钟祥市| 黔江区| 松溪县| 玉屏| 长白| 沙洋县| 温宿县| 石狮市| 礼泉县| 保定市| 博爱县| 邢台市| 乌海市| 高唐县| 阳新县| 会泽县| 三台县| 岳池县| 溧水县| 伊川县| 禄劝| 宝清县| 迁西县| 绥德县| 稻城县| 虹口区| 大邑县| 五河县| 和静县| 全南县| 唐山市| 吴忠市| 营口市| 昆明市| 双辽市| 上蔡县| 沅江市| 富平县|