以编程方式在Android上欺骗MAC地址

时间:2013-12-11 09:41:20

标签: java android

我做了一个小应用程序,允许你欺骗Android设备的mac地址。命令 “ip link set wlan0 down”,“ip link set wlan0 address NE:WM:AC“,”ip link set wlan0 up“,”ip link“在android终端模拟器中完美运行,但第二个在应用程序中不起作用:( 实际上MAC没有改变

String[] commands = { "ip link set wlan0 down" , "ip link set wlan0 address NE:WM:AC" , "ip link set wlan0 up", "ip link" }
@Override
protected void onCreate(Bundle savedInstanceState) {
   super .onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   addListenerOnButton();
}
public void addListenerOnButton() {
   button = (Button) findViewById(R.id.button1);
   button.setOnClickListener( new OnClickListener() {
      public void onClick(View arg0) {
         try {
            RunAsRoot(commands);
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
      }
   });
}
public void RunAsRoot(String[] cmds) throws IOException{
   Process p = Runtime.getRuntime().exec( "su" );
   DataOutputStream os = new DataOutputStream(p.getOutputStream());
   for (String tmpCmd : cmds) {
      os.writeBytes(tmpCmd+ " \n " );
   }
   BufferedReader in = new BufferedReader( new InputStreamReader(p.getInputStream()));
   String line = null;
   while ((line = in.readLine()) != null) {
      Log.i(line,line);
   }
   os.writeBytes( "exit \n " );
   os.flush();
}

0 个答案:

没有答案
相关问题