View Wifi password for Android

Source: Internet
Author: User

On the Android phone, after connecting to Wifi, the password is generally invisible. Is there any way to view these passwords? There are two methods. One is to view the wifi configuration file and the other is to use commands. For the first type, there are already a lot of online tools, namely, root first, and then use tools such as mobile assistant or mobile phone File Viewing (such as ES and Root Exploere) to view the wifi configuration file (the location is data/misc/wifi. The directory contains wpa_supplicant.conf or other file names. conf file ).

However, this method may sometimes cause some problems. For example, when the root of the mobile phone is not thorough enough, unexpected problems may occur. For example, when we use the root tool to root the Xiaomi phone, it seems that the root is successful, but it will cause some problems, such as authorization problems, wifi unavailability, and the phone cannot be connected to the computer.

If this method is not used, what else can be used? This is the topic of today. The second method to view the Wi-Fi password is the command.

Let's take a look:


, We can see that, after entering the command in turn, we get the user name (test) and password (12345) of wifi ). Now let's look at these commands.

1. adb connect 192.168.1.6. This is to use adb to connect to the mobile phone. If adb is not configured in the environment variable, first locate the directory where adb is located, and then execute this command or add the directory to the environment variable.

2. adb shell. This is the command terminal for starting the mobile phone. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + signature + vNDPwsv509Bjb25mzsS8/Signature + signature/PwsPmysfKtc/WtcS0 + sLroaM8L3A + signature + Signature = "brush: java;"> package com. example. wifipassword; import java. io. bufferedReader; import java. io. dataInputStream; import java. io. dataOutputStream; import java. io. inputStreamReader; import java. util. arrayList; import java. util. list; import java. util. regex. matcher; import java. util. regex. pattern; public class WifiManage {public List Read () throws Exception {List WifiInfos = new ArrayList (); Process process = null; DataOutputStream dataOutputStream = null; DataInputStream dataInputStream = null; StringBuffer wifiConf = new StringBuffer (); try {process = runtime.getruntime(cmd.exe c ("su "); dataOutputStream = new DataOutputStream (process. getOutputStream (); dataInputStream = new DataInputStream (process. getInputStream (); dataOutputStream. writeBytes ("cat/data/misc/wifi /*. conf \ n "); dataOutputStre Am. writeBytes ("exit \ n"); dataOutputStream. flush (); InputStreamReader inputStreamReader = new InputStreamReader (dataInputStream, "UTF-8"); BufferedReader bufferedReader = new BufferedReader (inputStreamReader); String line = null; while (line = bufferedReader. readLine ())! = Null) {wifiConf. append (line);} bufferedReader. close (); inputStreamReader. close (); process. waitFor ();} catch (Exception e) {throw e;} finally {try {if (dataOutputStream! = Null) {dataOutputStream. close ();} if (dataInputStream! = Null) {dataInputStream. close ();} process. destroy () ;}catch (Exception e) {throw e ;}} Pattern network = Pattern. compile ("network =\{ ([^ \}] +) \\}", Pattern. DOTALL); Matcher networkMatcher = network. matcher (wifiConf. toString (); while (networkMatcher. find () {String networkBlock = networkMatcher. group (); Pattern ssid = Pattern. compile ("ssid = \" ([^ \ "] +) \" "); Matcher ssidMatcher = ssid. matcher (networkBlock); if (ssidMatcher. find () {WifiInfo wifiInfo = new WifiInfo (); wifiInfo. ssid = ssidMatcher. group (1); Pattern psk = Pattern. compile ("psk = \" ([^ \ "] +) \" "); Matcher pskMatcher = psk. matcher (networkBlock); if (pskMatcher. find () {wifiInfo. password = pskMatcher. group (1);} else {wifiInfo. password = "no Password";} wifiInfos. add (wifiInfo) ;}} return wifiInfos ;}}
WifiInfo. java

package com.example.wifipassword;public class WifiInfo {public String Ssid="";public String Password="";}


Note:

1、get the root permission through runtime.getruntime(cmd.exe c ("su.

2. Use process. getOutputStream () and process. getInputStream () to obtain the input stream and output stream of the terminal.

3. Enter the command in the terminal through dataOutputStream. writeBytes ("cat/data/misc/wifi/*. conf \ n. Note: \ n must be used as the line feed. Otherwise, it will be used as a command with the last exit command, resulting in command execution failure and no result.

4. Get the command execution result through dataInputStream and convert it into a string using the UTF-8 encoding.

5. Use the regular expression to filter out the Wi-Fi user name and password.

The code for displaying the password is attached:

Package com. example. wifipassword; import java. util. list; import android. app. activity; import android. content. context; import android. OS. bundle; import android. view. layoutInflater; import android. view. view; import android. view. viewGroup; import android. widget. baseAdapter; import android. widget. listView; import android. widget. textView; public class MainActivity extends Activity {private WifiManage wifiManage; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); wifiManage = new WifiManage (); try {Init ();} catch (Exception e) {// TODO Auto-generated catch blocke. printStackTrace () ;}} public void Init () throws Exception {List
 
  
WifiInfos = wifiManage. read (); ListView wifiInfosView = (ListView) findViewById (R. id. wifiInfosView); WifiAdapter ad = new WifiAdapter (wifiInfos, MainActivity. this); wifiInfosView. setAdapter (ad);} public class WifiAdapter extends BaseAdapter {List
  
   
WifiInfos = null; Context con; public WifiAdapter (List
   
    
WifiInfos, Context con) {this. wifiInfos = wifiInfos; this. con = con ;}@ Overridepublic int getCount () {// TODO Auto-generated method stubreturn wifiInfos. size () ;}@ Overridepublic Object getItem (int position) {// TODO Auto-generated method stubreturn wifiInfos. get (position) ;}@ Overridepublic long getItemId (int position) {// TODO Auto-generated method stubreturn position ;}@ Overridepublic View getView (int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubconvertView = LayoutInflater. from (con ). inflate (android. r. layout. simple_list_item_1, null); TextView TV = (TextView) convertView. findViewById (android. r. id. text1); TV. setText ("Wifi:" + wifiInfos. get (position ). ssid + "\ n password:" + wifiInfos. get (position ). password); return convertView ;}}}
   
  
 

Finally:

View Wifi password for Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.