JAVA中如何读取主板序列号或硬盘序列号或MAC地址

本文提供了一种使用Java代码来获取计算机网络适配器的物理地址(MAC地址)的方法。通过调用系统的ipconfig命令并解析其输出,实现了从Windows环境中读取物理地址的功能。

from:http://ywh5.bokee.com/viewdiary.13113717.html

 

private   String   getPhysicalAddress() {  
          String   cmd   =   "cmd.exe   /c   ipconfig/all";  
          String   strRs="";  
          String   result="";  
          strRs=executeSysCMD(cmd);  
          result   =   parseCmd(strRs);  
          return   result;   
}

 

private   String   executeSysCMD(String   shellCommand)   {  
          try   {  
              Start(shellCommand);  
              StringBuffer   sb   =   new   StringBuffer();  
              DataInputStream   in   =   new   DataInputStream(p.getInputStream());  
              BufferedReader   reader   =   new   BufferedReader(new   InputStreamReader(in));  
              String   line;  
              do   {  
                  line   =   reader.readLine();  
                  if   (line   ==   null)   {  
                      break;  
                  }  
                  else   {  
                      sb.append(line);  
                  }  
              }  
              while   (true);  
              reader.close();  
              return   sb.toString();  
          }  
          catch   (Exception   e)   {  
              //error  
              return   null;  
          }  
}


private   String   parseCmd(String   s)   {  
          String   find   =   "Physical   Address.   .   .   .   .   .   .   .   .   :";  
          int   findIndex   =   s.indexOf(find);  
          if   (findIndex   ==   -1)  
              return   "not   find";  
          else  
              return   s.substring(findIndex   +   find.length()   +   1,   
                                   findIndex   +   find.length()   +   1   +   _physicalLength);  
}

你可以通过这个链接引用该篇文章:http://ywh5.bokee.com/tb.b?diaryId=13113717

看到这篇文章 转贴一下!!晚上回来进行验证正确性!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值