2 qq 34150327 qq_34150327 于 2016.03.05 20:23 提问

红米手机如何找到imac地址

为什麽红米手机无法找到imac地址 为什麽红米手机无法找到imac地址

2个回答

lx624909677
lx624909677   Ds   Rxr 2016.03.07 16:48
已采纳
 //根据busybox获取本地Mac
     public static String getLocalMacAddressFromBusybox(){   
         String result = "";     
         String Mac = "";
         result = callCmd("busybox ifconfig","HWaddr");

         //如果返回的result == null,则说明网络不可取
         if(result==null){
             return "网络出错,请检查网络";
         }

         //对该行数据进行解析
         //例如:eth0      Link encap:Ethernet  HWaddr 00:16:E8:3E:DF:67
         if(result.length()>0 && result.contains("HWaddr")==true){
             Mac = result.substring(result.indexOf("HWaddr")+6, result.length()-1);
             Log.i("test","Mac:"+Mac+" Mac.length: "+Mac.length());

             /*if(Mac.length()>1){
                 Mac = Mac.replaceAll(" ", "");
                 result = "";
                 String[] tmp = Mac.split(":");
                 for(int i = 0;i<tmp.length;++i){
                     result +=tmp[i];
                 }
             }*/
             result = Mac;
             Log.i("test",result+" result.length: "+result.length());            
         }
         return result;
     }   

     private static String callCmd(String cmd,String filter) {   
         String result = "";   
         String line = "";   
         try {
             Process proc = Runtime.getRuntime().exec(cmd);
             InputStreamReader is = new InputStreamReader(proc.getInputStream());   
             BufferedReader br = new BufferedReader (is);   

             //执行命令cmd,只取结果中含有filter的这一行
             while ((line = br.readLine ()) != null && line.contains(filter)== false) {   
                 //result += line;
                 Log.i("test","line: "+line);
             }

             result = line;
             Log.i("test","result: "+result);
         }   
         catch(Exception e) {   
             e.printStackTrace();   
         }   
         return result;   
     }
devmiao
devmiao   Ds   Rxr 2016.03.05 23:50
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!