posts - 35,  comments - 6,  trackbacks - 0
             1import java.io.BufferedReader;  
             
          2import java.io.IOException;  
             
          3import java.io.InputStreamReader;  
             
          4import java.util.Properties;  
             
          5import java.util.logging.Level;  
             
          6import java.util.logging.Logger;  
             
          7.   
             
          8public class Test {  
             
          9.   
            
          10.     public static String getMACAddress() {  
            
          11.   
            
          12.          String address = "";  
            
          13.          String os = System.getProperty("os.name");  
            
          14.          System.out.println(os);  
            
          15.         if (os != null) {  
            
          16.             if (os.startsWith("Windows")) {  
            
          17.                 try {  
            
          18.                      ProcessBuilder pb = new ProcessBuilder("ipconfig""/all");  
            
          19.                      Process p = pb.start();  
            
          20.                      BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));  
            
          21.                      String line;  
            
          22.                     while ((line = br.readLine()) != null) {  
            
          23.                         if (line.indexOf("Physical Address"!= -1) {  
            
          24.                             int index = line.indexOf(":");  
            
          25.                              address = line.substring(index + 1);  
            
          26.                             break;  
            
          27.                          }  
            
          28.                      }  
            
          29.                      br.close();  
            
          30.                     return address.trim();  
            
          31.                  } catch (IOException e) {  
            
          32.                       
            
          33.                  }  
            
          34.              }else if(os.startsWith("Linux")){  
            
          35.                 try {  
            
          36.                      ProcessBuilder pb = new ProcessBuilder("ifconfig");  
            
          37.                      Process p = pb.start();  
            
          38.                      BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));  
            
          39.                      String line;  
            
          40.                     while((line=br.readLine())!=null){  
            
          41.                         int index=line.indexOf("硬件地址");  
            
          42.                         if(index!=-1){  
            
          43.                              address=line.substring(index+4);  
            
          44.                             break;  
            
          45.                          }  
            
          46.                      }  
            
          47.                      br.close();  
            
          48.                     return address.trim();  
            
          49.                  } catch (IOException ex) {  
            
          50.                      Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);  
            
          51.                  }  
            
          52.                   
            
          53.              }  
            
          54.          }  
            
          55.         return address;  
            
          56.      }  
            
          57.   
            
          58.     public static void main(String[] args) {  
            
          59.          System.out.println("" + Test.getMACAddress());  
            
          60.      }  
            
          61. } 
          posted on 2009-09-14 10:00 NG 閱讀(253) 評論(0)  編輯  收藏

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


          網站導航:
           
          <2009年9月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          常用鏈接

          留言簿(1)

          隨筆檔案(35)

          文章分類(5)

          文章檔案(2)

          新聞檔案(5)

          java link

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 子洲县| 巴东县| 始兴县| 仙居县| 天祝| 镇坪县| 邢台市| 都兰县| 利川市| 汉寿县| 泌阳县| 天长市| 茂名市| 宜阳县| 晋中市| 麻栗坡县| 奉化市| 张家口市| 张掖市| 横峰县| 多伦县| 金川县| 安丘市| 祁阳县| 柳河县| 大足县| 马公市| 资源县| 买车| 郑州市| 武鸣县| 开封市| 沈丘县| 大邑县| 和硕县| 托克逊县| 阿克陶县| 垣曲县| 宁夏| 天峨县| 临湘市|