俊星的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 俊星 阅读(328) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: