Is there a way to get the configured WiFi-SSIDS from an Android (not rooted) device via ADB? This should be working independant from the WiFi on/off state.
Thank you
generally all the configured WIFIs with their passwords are stored in wpa_supplicant.conf which saved in
/data/misc/wifi/wpa_supplicant.conf
but you cant access it unless you have root permission.
you can pull the file by this command
if using windows
adb pull /data/misc/wifi/wpa_supplicant.conf c:\
if using ubuntu
adb pull /data/misc/wifi/wpa_supplicant.conf ~/
Finally found out that
adb shell dumpsys wifi | grep -i ssid
gives the configured wifis
Edit: Only if wifi is enabled
Not possible. WifiManager.getConfiguredNetworks() only works when WiFi is on.
adb pull does work on unrooted devices. u need to run the command as root first. try the following:
in the same command prompt box,
-type [adb root] to restart adb as root. click enter.
-Now type [adb shell], click enter. makes sure the prompt shows [root#[device]: ]
-At the # prompt type [cd /data/misc/wifi] click enter.
-Lastly type [cat wpa_supplicant.conf] click enter.
this should dump data of WiFi you've previously connected to on your phone, to your pc screen.
*type in without brackets []
these command works on my unrooted device after running into the “remote object does not exist” issue.
Related
I have some old shell scripts that needs to be executed on an android device but the command to fetch the total cpu, memory and swap usage is top. More specific it is:
top -m 1 -d 1.0 -n $duration
Now I have been looking to find a replacement for this and I found out that I can use dumpsys. The problem what I have is that I want to give a timeout like this:
dumpsys -t 20 cpuinfo
I checked this site: https://developer.android.com/studio/command-line/dumpsys.html but didn't find out why this doesn't work. Even when I try the help I get the same error
dumpsys --help
Can't find the service: --help
Does someone know what is going on? My current android version is 6.0.1 if this is important.
Thanks in advance!
It is true that dumpsys --help does not work. I think there is a mistake in their document. However, below works:
# adb shell dumpsys input
# adb shell dumpsys -l
Add permission on your manifest "android.permission.DUMP".or
There's another (hacky) way to access dumpsys without rooting your device - through adb shell.
This will require allowing USB debugging, and finding the port of the adb service.
Enable USB debugging on your device. This option is found under Settings -> Developer Options.
Connect your device to a PC, and run the following command from the PC's shell/command line: adb tcpip 12345. Then, from your devices shell, issue the command adb connect localhost:12345 from your application. You can now disconnect the device from USB. Alternatively, you can scan the ports on your device one by one without USB connection, using adb connect localhost: and find the port adb service is listening to.
Authorize USB debugging from the pop up confirmation dialog, if prompted. Check the "always" checkbox to do not require this step again.
Now, when you have access to the adb service, use adb shell dumpsys ... from your application code to get whatever service dump you need.
I understand we could turn off Wifi through the "adb shell svc wifi disable" command but I don't want to completely turn off Wifi. I want to disconnect from a particular ssid through adb. Is it possible?
Edit: I got a notification saying this question is identified as a dupe of this question: How to turn off Wifi via ADB?. It actually is not. As mentioned clearly in the first paragraph, I don't want to turn off wifi but want to simply disconnect from a particular network. This is like long pressing a network and tapping "Forget network". Essentially I want to simulate a condition of the user moving out of a wifi network without having to turn off wifi.
If you have root access, you can make it by using wpa_cli.
First, you can use the wpa_cli`s list_networks to get the network id of the network that you want to disconnect
$ adb shell
# wpa_cli
> list_networks
**network id** / ssid / bssid / flags
0 001aLinksys14081-2G any [CURRENT]
and then you just need to run the wpa_cli remove_network {network id}, where the {network id} parameter is the one that you got on the list_networks method.
One option is to use cmd wifi. For disconnecting from a Wi-Fi network, you can "forget" it like so:
adb shell cmd wifi list-networks
adb shell cmd wifi forget-network <networkId from list-networks>
You can view the help documentation for cmd wifi with:
adb shell cmd wifi -h
This command did it for me
docker exec -it $container_id /bin/bash -c "cd /root//shared-tools/android-sdk/platform-tools; ./adb shell 'svc wifi disable'"
You cannot. But, this will not be enough to satisfying your question, there is tricky way to connect to "other wifi". (Yes, it is not disconnect)
Install an app, and send command to the app via adb.
See this: https://stackoverflow.com/a/37303412/850347
I already build an app which does so and it's available here: https://github.com/steinwurf/adb-join-wifi
Once the app is installed, a wifi access point can be joined using the following ADB command:
adb shell am start -n com.steinwurf.adbjoinwifi/com.steinwurf.adbjoinwifi.MainActivity -e ssid [SSID] -e password_type [PASSWORD_TYPE] -e password [WIFI PASSWORD]
See this: https://stackoverflow.com/a/37303412/850347
I have a little script that I run in adb shell of Android phone (/system/etc directory), which enables to communicate with the modem by sending/receiving a single AT command.
The script itself, if run in adb shell, works OK. That's what it looks like:
cat /dev/pts/7 &
echo -e $1\\r > /dev/pts/7
Here's the output in adb shell:
# ./sendATCommand "at+cops?"
./sendATCommand "at+cops?"
#
+COPS: 0,0,"AT&T",6
OK
/dev/pts/7: invalid length
(need to press ENTER to return control to adb shell)
#
Now I want to invoke this script from a powershell script running on my PC, thus eventually controlling modem via AT commands, but nothing happens.
For example, the below powershell script will send the command at+cops? to check the operator to which mobile is registered to:
$adb = [IO.Path]::Combine([IO.Path]::Combine($Env:ANDROID, "platform-tools"), "adb.exe")
& $adb remount
$atCommand = "at+cops?"
& $adb shell /system/etc/sendATCommand $atCommand
The output may looks sometimes like +ATCMD (any residual [proprietary]AT command sitting in device buffer after bootup), or at+cops?(echo), or nothing at all, but
never +COPS: 0,0,"AT&T",6 which I expect. Could you help me figure out what's going on and how to possibly fix it? Ideally
I want to be able to execute at command, return control to powershell, and have output available for further processing.
I am also open to other solutions to implement same thing.
Would greatly appreciate your help. Thanks!
Not sure to answer your question, my phone is not an Android, but when I connect it via buetooth or USB to my computer a COM port is created. So I build an assembly tool on the top of .NET SerialPort class that allow, for example, to send SMS using the phone Modem.
I think it's usable in your case.
I have tried the navigate to the android tool folder and entering the "adb shell" command but it doesn't seem to work. My terminal seems only to recognize the adb part of the command and gives me an error message. What am I doing wrong???
List all connected devices by typing adb devices
Check, if there are any devices listed. If not you may want to check that your device is connected and/or your emulator is running.
If it works and you have for example your emulator running and your usb-device connected use:
adb shell if you only have device connected.
adb -d shell to connect to an USB-Device.
adb -e shell to connect to an emulated device.
If you have more than one emulator or usb devices you might want to use:
adb -s <DEVICE> shell
Note:
Make sure that the path to the android-sdk is properly set-up in your environment. To quickcheck, fire up a shell and type adb version. If that command succeeds, you're set up. If not, add /path/to/android-sdk/tools and /path/to/android/platform-tools to your $PATH env variable. On windows the android sdk is typically located in C:\Users\<username>\AppData\Local\Android\sdk.
Is it possible to get android device info (e.g. firmware version) from windows, when device is connected with PC by USB cable?
As I understand AT commands are not available. I was trying to use "adb", but I cannot see any usefull options. Maybe there is some text file with device info on the filesystem of the phone, so I could use "adb shell" to read this file?
Regards!
Use for example
adb -e shell getprop ro.build.display.id
to obtain something like
sdk-eng 2.1 ERD79 22607 test-keys
If you have more than one device or emulator, use
adb devices
to identify them and then use -s serialno in adb command line