MacAddressAccess

记录下来,省得下次使用时还得查找。
 
  1. import java.io.*;   
  2. public class MacAddressAccess {  
  3.     public MacAddressAccess() {   
  4.     }  
  5.     private static String getMyMac() {  
  6.         String s = "";  
  7.         try {  
  8.             String s1 = "ipconfig /all";  
  9.             // 相当于在命令行下直接使用ipconfig /all  
  10.             Process process = Runtime.getRuntime().exec(s1);   
  11.             BufferedReader bufferedreader = new BufferedReader(new   
  12.                        InputStreamReader(process.getInputStream()));  
  13.             String line = bufferedreader.readLine();  
  14.             // 筛选出mac地址  
  15.             for(;line != null;) {  
  16.                 String nextLine = bufferedreader.readLine();  
  17.                 if(line.indexOf("Physical Address") > 0){   
  18.                     int i = line.indexOf("Physical Address") + 36;   
  19.                     s = line.substring(i);   
  20.                     break;   
  21.                 }  
  22.                 line = nextLine;   
  23.             }  
  24.             bufferedreader.close();  
  25.             process.waitFor();  
  26.         } catch(Exception exception) {  
  27.             s = "";  
  28.         }  
  29.         return s.trim();  
  30.     }  
  31.     public static void main(String[] args){   
  32.         // 显示Mac地址在命令行界面  
  33.         System.out.println(MacAddressAccess.getMyMac());  
  34.     }  
  35. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值