android 获取wifi 密码 代码

 想要获取wifi密码首先要保证你的手机已经root、 因为只有root 以后才能读取存放密码的配置文件

    如果你的手机已经root 用该语句获取 使你的程序获取权限           Process process = Runtime.getRuntime().exec("su");


  下面是  程序的布局

   

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="152dp"
        android:text="获取密码" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="101dp"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="71dp"
        android:text= "退出"/>

</RelativeLayout>


下面是程序的代码

package com.android.getpsk;


import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
	Button myButton;
	Button quit;
	TextView show;
	MyHandler myHandler;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		myButton = (Button) findViewById(R.id.button1);
		quit = (Button) findViewById(R.id.button2);
		show  = (TextView)findViewById(R.id.textView1);
		myHandler = new MyHandler();
		myButton.setOnClickListener(new OnClickListener() {
        	public void onClick(View v)
        	{      		
        		Log.e("Fuck", "I got a key down");   	
        		MyThread m = new MyThread();
                new Thread(m).start();
        	}
        });
		quit.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
			
		});
	}
	
	 @SuppressLint("HandlerLeak")
	class MyHandler extends Handler {

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
			Bundle b = msg.getData();
            String info = b.getString("info");
            MainActivity.this.show.setText(info);
            
		}
		 
	 }
	
	
	class MyThread implements Runnable {
        public void run() {
           ;
            StringBuilder content = new StringBuilder();
			try {
			 Process 	process = Runtime.getRuntime().exec("su");			
				String cmd = "cat /data/misc/wifi/wpa_supplicant.conf";
				//String cmd = "id";
				DataOutputStream dataOutputStream = new DataOutputStream(process.getOutputStream());
				DataInputStream dataIntputStream = new DataInputStream(process.getInputStream());
				DataInputStream dataErrorStream = new DataInputStream(process.getErrorStream());
				dataOutputStream.writeBytes(cmd + "\n");			
				dataOutputStream.flush();
				Thread.sleep(2000);
				
				String line = "";
				if (dataIntputStream.available() > 0)
				{
					String error = "";
					
					int total = dataIntputStream.available();
					Log.e("TotalCount", Integer.toString(total));
					int i = 0;
					while(i < total)
					{	
						
						line = dataIntputStream.readLine();
						if(line.trim().startsWith("ssid=") || line.trim().startsWith("psk="))
						{
							content.append(line + "\n");
						}
						
						i += line.length() + 1;
					}
					
					dataOutputStream.close();
					dataErrorStream.close();
					dataErrorStream.close();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				Log.e("Exception1", e.toString());
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				Log.e("Exception2", e.toString());
			}
                      
            Message msg = new Message();
            Bundle b = new Bundle();// 存放数据
            b.putString("info", content.toString());
            Log.e("info", content.toString());
            msg.setData(b);
            MainActivity.this.myHandler.sendMessage(msg); // 向Handler发送消息,更新UI
        }
    }



	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}


运行结果我就不截图了。我亲测是Ok 的  


转载自http://download.csdn.net/detail/chw_611/5275223

展开阅读全文

获取wifi密码

06-13

rn使用kali破解(自家)无线rn0x00 破解思路rnrn1.探测周围无线,寻找目标wifirn2.对目标发起攻击以获得密码信息文件rn3.使用字典对抓取的数据进行离线破解rn0x01 使用过程rn1.开启 aircrack-ng 工具rn[img=https://img-bbs.csdn.net/upload/201706/13/1497339076_668974.png][/img]rn2.扫描附近wifirn[img=https://img-bbs.csdn.net/upload/201706/13/1497339124_194896.png][/img]rn#命令为红色部分rn3.找到目标rn[img=https://img-bbs.csdn.net/upload/201706/13/1497339236_84692.png][/img]rn#我们这里选择我自己的无线(尾部mac地址为C8的无线)rnrn#黄色部分是需要注意的信息,下边要用到!rnrn#这样扫面会显示附近所有的无线信息,上半部分为无线状态信息,下半部分为连接客户端信息,这里因为数据量太大,下别需要的信息被挤下去了,因此我们要改用筛选扫描,rn4. 对目标进行筛选扫面rn[img=https://img-bbs.csdn.net/upload/201706/13/1497339308_70203.png][/img]rnrn[img=https://img-bbs.csdn.net/upload/201706/13/1497339342_72746.png][/img]rn#输入以上命令后看到的信息,第一个框为目标mac地址,第二个框(下边)为目标客户端rn5.抓取无线密码信息文件rn[img=https://img-bbs.csdn.net/upload/201706/13/1497339418_516945.png][/img]rn# –ivs : 保存文件格式rnrn# -w : 保存文件名rnrn# –bssid :为目标mac地址rnrn# -c : 无线信道,之前圈到的信息里!rnrn#输入命令后注意黄色部分rn6.开始对目标开启攻击rn[img=https://img-bbs.csdn.net/upload/201706/13/1497339463_993329.png][/img]rn#第一个mac地址为目标无线mac地址,后者为客户端mac地址rnrn rn7.获得密码信息文件rn[img=https://img-bbs.csdn.net/upload/201706/13/1497339487_614718.png][/img]rn#如出现上图红色部分,则表示已经抓取到无线密码信息文件rnrn rn8.开始破解抓取的密码文件rn[img=https://img-bbs.csdn.net/upload/201706/13/1497339513_118323.png][/img]rn#这里请大家自行准备密码本,我这里的密码本叫做 pass.txtrnrn rnrn#最后获得无线密码rn[img=https://img-bbs.csdn.net/upload/201706/13/1497339542_770076.png][/img]rnrn此方法可以破解比较简单的密码,过于复杂的密码因为加密方式问题暴力破解花费时间较长,很不容易破解。rn rn0x02 声明rn本文仅供大家学习探讨及交流,任何使用本文内容进行涉及违法犯罪的行为及一切后果,与本文及作者无关。rnrn本文转自http://www.bangcleedu.com/412rn 论坛

没有更多推荐了,返回首页