`
zccmp
  • 浏览: 8178 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

java获取MAC地址

阅读更多


Java代码 
package com;  
 
import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.util.Properties;  
 
public class Test {  
 
/** 
* @param args 
* @throws IOException  
*/ 
public static void main(String[] args) throws IOException {  
   // TODO Auto-generated method stub  
   Properties pp = System.getProperties(); //获取系统的所有属性  
   pp.list(System.out);//打印所有的属性  
   String command = "cmd.exe /c ipconfig/all ";  
   Process p = Runtime.getRuntime().exec(command);//执行DOS程序  
    
   System.out.println(p);  
   BufferedReader br = new BufferedReader(new InputStreamReader(p  
     .getInputStream()));  
   String line;  
   String address = "";  
   while ((line = br.readLine()) != null) {  
    System.out.println(line);  
    if (line.indexOf("Physical Address") > 0) {//如果有Physical Address字符串  
     int index = line.indexOf(":");  
     index += 2;  
     address = line.substring(index);  
     break;  
    }  
   }  
   br.close();  
 
   System.out.println(address);  
    
}  
 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics