How can I programmatically read wifi passwords in Android

筅森魡賤 提交于 2020-01-21 04:23:32

问题


I am trying to get the WiFi passwords programmatically from a non-rooted Android device.

All I need is to be able to read the passwords, I do not need to be able to edit them.

Can I get permission in the manifest file?


回答1:


If your application is a privileged app (that is - installed in /system/priv-app for example using SuperUser) then you can use the new WifiManager#getPrivilegedConfiguredNetworks() API in Lollipop and newer.

See: https://android.googlesource.com/platform/frameworks/base/+/758bdf4a915c313f1c3bef0b95b494c91f363f03%5E%21/#F1




回答2:


This is not possible as this would be a major security risk.

You may be able to if the phone is rooted but I do not know, I would imagine, and hope, even if you could get to where it is stored on the phone, it would be encrypted.




回答3:


Most of the time, the Wi-Fi credentials are managed by the wpa_supplicant daemon which store this in a configuration file like /data/misc/wifi/wpa_supplicant.conf.

In this file you will find network structures which store the remembered networks like this:

network={
    ssid="example"
    key_mgmt=WPA-PSK
    psk="passphrase"
}

This file is usually own by a system user like wifi or root. So you have to be root if you want to read it directly.

Nevertheless, you can get the ssid or other network variables of the remember networks by using the wpa_cli command:

$ wpa_cli get_network <id> ssid
"example"

But if you try with the psk you will get a * as this is a security risk:

$ wpa_cli get_network <id> psk
*



回答4:


There is no API support for reading/writing WiFi passwords for APKs not signed with the system key. So you won't be able to retrieve it.



来源:https://stackoverflow.com/questions/21330520/how-can-i-programmatically-read-wifi-passwords-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!