Connect Android phone over Wi-Fi using ADB - Android Q&A, Help & Troubleshooting

(Many will consider this question a duplicate of similar questions but I don't think this question should be marked as duplicate because the answer requested here is different than others.)
I am searching for the solutions since many years and read a lot of pages on internet and StackOverflow but hasn't found any solution.
Once an non-rooted Android phone is authorized over USB using ADB then how to connect it over Wi-Fi every time without ever connecting the phone over USB?
I know that executing
Code:
adb start-server
then
Code:
adb tcpip 5555
and then
Code:
adb connect <IP.address.of.phone>
will connect the phone over Wi-Fi IF it is connected using USB when issuing these commands.
According to the answers/forums, there are 2 ways to connect Android phone over Wi-Fi:
The user has to first connect to USB even though the device is already authorized.
The phone needs to be rooted.
But I think, what I want to achieve, as per the question, must be possible because if ADB can connect over USB and then Wi-Fi, then there must be some way to accomplish with directly connecting over Wi-Fi if computer is already authenticated. The missing thing is to know what exactly ADB is doing when switching from USB to Wi-Fi. I think, it could be getting authorization again. But what if we store the authorization information (finger print? or encryption key?) once and use it every time to connect over Wi-Fi? (Please note that when first time authenticating the computer over USB, its finger print is showed in the Android phone, and it never asks again until the authorization is revoked/invalidated somehow. So, I think the requirement here is to revalidate the computer.)
I viewed the ADB repository and read the text files mentioning how ADB works. In one txt file I read that
Code:
adbd
(ADB Daemon) is started on port 5555 on the Android phone/emulator when
Code:
adb connect ___
command is executed. Is there anyway to manually start the daemon through a terminal app on the installed on phone? I tried 'adb', 'adbd' and 'setprop' commands in the Termux app but these commands doesn't exist. According to the txt files of the repository, the ADB on computer is sending the commands to the Android device/emulator and can start 'adbd' or set/open the port 5555 using
Code:
setprop service.adb.tcp.port 5555
command. Is there a way to do this on Android phone using a terminal app on a non-rooter phone?
Somebody who has knowledge of networking, Android and C/C++ language may be able to answer. One can look in the GitHub repo of ADB source code if they want to know what is happening during the connection process.

I'm a little late to answer your question at the time you asked it, but if it still helps the OP, non-rooted Android 10 and below allowed wireless adb connections AFTER a USB connection was first established (adb start-server && adb tcpip 5555 && adb connect [IP]:5555), but that changed (for the better) in Android 11 and above with the new new Developer options Wireless debugging random port assignments (adb connect [IP]:[PORT] or adb pair [IP]:[PORT] [PIN]) such that the adb wireless connection never needs USB cable ever again.
Given Android 11 allows Developer options Wireless debugging via a random port, and Android 12 new Developer options Wireless debugging allows that to be accessed even easier with a new Developer options Wireless debugging tile, the only thing missing is a way to get, after the fact, the random port assignment that Android uses for the adb wireless connection to your PC.
Here are some related posts about that subject which may help the OP.
[adb,scrcpy,vysor] What ports does Android 12 randomly set when Wi-Fi connecting via Wireless debugging adb "pair" or "connect" commands?
(PSA) Using the new Android 12 TILE for 'Developer options' 'Wireless debugging' to establish adb connection over Wi-Fi without USB
What's the difference between Windows/Android adb "connect" versus adb "pair" when mirroring Android 12 over Wi-Fi onto a Windows PC?
The only question that's missing an answer preventing a perfect solution is...
Does anyone know how to obtain that random Android port address from the PC?

Related

[REQUEST] Wireless ADB

The Barnes & Noble Nook uses adb over wifi. How can I setup my N1 to do the same? Ideally I would like to specify on the N1 to only allow connections over wifi, and if possible have some sort of password type security. Can this be done?
why not use ssh?
the dropbear-client is included in most custom roms.
edit: i mean dropbear-server of course
mikecyber said:
The Barnes & Noble Nook uses adb over wifi. How can I setup my N1 to do the same? Ideally I would like to specify on the N1 to only allow connections over wifi, and if possible have some sort of password type security. Can this be done?
Click to expand...
Click to collapse
+1 on this, but I would like it to be included within the ROM with a UI setting or maybe even an applicaion
Getting adbd to listen to tcpip in the phone is quite easy.
Example below:
Code:
[I]# detach adbd from usb and tell it to listen to port tcp 2222
[/I][email protected]$ adb tcpip 2222
restarting in TCP mode port: 2222
[I]# tell your local adb command to use ip:port to connect through instead of usb (192.168.0.151 is my N1 on Wifi)
[/I][email protected]$ adb connect 192.168.0.151:2222
connected to 192.168.0.151:2222
[I]# connect over ip
[/I][email protected]$ adb shell
# uname -a
Linux localhost 2.6.29.6-cyanogenmod #3 PREEMPT Wed Jan 27 07:21:12 EST 2010 armv7l GNU/Linux
# exit
[I]# tell adbd to go back to listen on usb
[/I][email protected]$ adb usb
restarting in USB mode
packetlss said:
Getting adbd to listen to tcpip in the phone is quite easy.
Click to expand...
Click to collapse
Thank you, your method works well.
With my nook all I need to do is "adb connect 192.168.1.x:5555" I don't have to put adb into tcpip mode or enter "uname -a" in shell.
I would love to see "Wireless Debugging" in Settings -> Applications -> Development, or really anywhere in Settings. I haven't voided my N1's warranty, so an app to add this functionality would be great.
mikecyber said:
Thank you, your method works well.
With my nook all I need to do is "adb connect 192.168.1.x:5555" I don't have to put adb into tcpip mode or enter "uname -a" in shell.
I would love to see "Wireless Debugging" in Settings -> Applications -> Development, or really anywhere in Settings. I haven't voided my N1's warranty, so an app to add this functionality would be great.
Click to expand...
Click to collapse
That's because the nook adbd is configured to listen to tcp by default, on most other platforms it just listens to USB by default.
The 'uname -a' was just to show that I actually was connected to the phone. Nothing to do with the actual adb stuff at all, I was just lazy and copied from my terminal
MoDaCo Custom ROMs generally run dropbear by default with a password that is randomly generated on first startup.
I don't mind making an addon update zip for Cyanogen's ROM with this functionality if you want it?
P
bump
Found this really useful as my USB driver causes BSODs. thanks packetlss
1. connect device via usb
2. adb tcpip 2222
3. connect over wifi. adb connect 192.168.3.5:2222
4. adb commands as normal
can the OP remove [request] as this is now a [tip] or [howto]
britoso said:
bump
Found this really useful as my USB driver causes BSODs. thanks packetlss
1. connect device via usb
2. adb tcpip 2222
3. connect over wifi. adb connect 192.168.3.5:2222
4. adb commands as normal
can the OP remove [request] as this is now a [tip] or [howto]
Click to expand...
Click to collapse
Does the USB have to be hooked up each time, or is it a 1 time then WIFI is good after that?
Nice howto!!
britoso said:
bump
Found this really useful as my USB driver causes BSODs. thanks packetlss
1. connect device via usb
2. adb tcpip 2222
3. connect over wifi. adb connect 192.168.3.5:2222
4. adb commands as normal
can the OP remove [request] as this is now a [tip] or [howto]
Click to expand...
Click to collapse
Gotta say that is slick as sh**!!! How to get it to stay on tcpip via terminal on phone??
britoso said:
bump
Found this really useful as my USB driver causes BSODs. thanks packetlss
1. connect device via usb
2. adb tcpip 2222
3. connect over wifi. adb connect 192.168.3.5:2222
4. adb commands as normal
can the OP remove [request] as this is now a [tip] or [howto]
Click to expand...
Click to collapse
interesseting... thanks!
i'll try that
EDIT: worked so good - thx!
tbirdguy said:
Does the USB have to be hooked up each time, or is it a 1 time then WIFI is good after that?
Click to expand...
Click to collapse
Do it once and it stays...perhaps till you reboot the phone.
If your IP address on wifi you will need to run the connect command again. Also set the wifi-sleep mode to 'never', possibly install the wifi-keepalive app.
Its awesome to be able to run stuff on your phone straight from eclipse, unplugged; or install/push/pull files
xkonni said:
why not use ssh?
the dropbear-client is included in most custom roms.
edit: i mean dropbear-server of course
Click to expand...
Click to collapse
Do you know what the default pw is for dropbear? when i try to ssh with my local ip and root, i get a connection refused on port 22. i'm using cm6, do i have to enable it somehow?
TCPIP mode without connecting usb
Is it possible to enable ADBD tcpip mode without connecting device to USB port and use adb command? I mean maybe a command we can run in a Terminal Emulator?
bohlool said:
Is it possible to enable ADBD tcpip mode without connecting device to USB port and use adb command? I mean maybe a command we can run in a Terminal Emulator?
Click to expand...
Click to collapse
re,it's there any possible that get adb work over TCP/IP ,on all android devices(include non-rooted devices)?
wobiu said:
re,it's there any possible that get adb work over TCP/IP ,on all android devices(include non-rooted devices)?
Click to expand...
Click to collapse
I know how to enable it, just connect it with usb to computer and enter "adb connect tcpip <port>" then disconnect usb and connect phone to wifi, find the ip of phone and on your computer type "adb connect <ip>:<port>"
my problem is how can I do the first step without usb cable, i.e. using a terminal emulator. I have root access.
bohlool said:
my problem is how can I do the first step without usb cable, i.e. using a terminal emulator. I have root access.
Click to expand...
Click to collapse
would love to see this as well, can anyone with expertise in the area let us know if this is at all possible?
# adbd
As root on the device returns
Cannot bind tcp 5037
Im not home so i cant test but maybe this could work over tcp port 5037...
Sent from my Nexus One
bohlool said:
I know how to enable it, just connect it with usb to computer and enter "adb connect tcpip <port>" then disconnect usb and connect phone to wifi, find the ip of phone and on your computer type "adb connect <ip>:<port>"
my problem is how can I do the first step without usb cable, i.e. using a terminal emulator. I have root access.
Click to expand...
Click to collapse
for rooted device。you can use"start adbd" command to start adb daemon ,instead of plug into usb.
What am i looking for is a way to use adb over wifi for all device including non-rooted.
wobiu said:
for rooted device。you can use"start adbd" command to start adb daemon ,instead of plug into usb.
What am i looking for is a way to use adb over wifi for all device including non-rooted.
Click to expand...
Click to collapse
What is the port number then? is it 5037? Can I set it somewhere? (for rooted devices of course)

How to make adb listen to tcpip 5555 after reboot

I have to use adb over ssh. now, everything works fine but after a reboot i have to connect my device again over usb and set adb to listen to tcpip instead of usb.
is ther a way to save those settings?
This is how it works for now. After a reboot i have to use these commands again (over usb) in order to establish an adb connection over ssh.
# adb kill-server
# adb tcpip 5555
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
restarting in TCP mode port: 5555
malufor said:
I have to use adb over ssh. now, everything works fine but after a reboot i have to connect my device again over usb and set adb to listen to tcpip instead of usb.
is ther a way to save those settings?
This is how it works for now. After a reboot i have to use these commands again (over usb) in order to establish an adb connection over ssh.
# adb kill-server
# adb tcpip 5555
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
restarting in TCP mode port: 5555
Click to expand...
Click to collapse
You can set service.adb.tcp.port=5555 in /default.prop or maybe /system/build.prop. But this isn't such a great idea, since it leaves you phone open to everybody wanting to gain shell access to it over the net.
And you don't need "adb kill-server" above. It's the devices adb you are restarting, not the one on your computer.
kuisma said:
You can set service.adb.tcp.port=5555 in /default.prop or maybe /system/build.prop. But this isn't such a great idea, since it leaves you phone open to everybody wanting to gain shell access to it over the net.
And you don't need "adb kill-server" above. It's the devices adb you are restarting, not the one on your computer.
Click to expand...
Click to collapse
Great thx. I'll give it a try.
Update:
Works perfectly. I modified the buil.prop. Thank you.
kuisma said:
You can set service.adb.tcp.port=5555 in /default.prop or maybe /system/build.prop. But this isn't such a great idea, since it leaves you phone open to everybody wanting to gain shell access to it over the net.
Click to expand...
Click to collapse
For tinkering purposes - well aware of the security implications here - I wanted to get adb to also listen on the mobile interface, when not connected to a wifi. Basically public debugging on the bus ride
I did not succeed though. How can adb be brought to listen on the mobile data connection?
schaggo said:
For tinkering purposes - well aware of the security implications here - I wanted to get adb to also listen on the mobile interface, when not connected to a wifi. Basically public debugging on the bus ride
I did not succeed though. How can adb be brought to listen on the mobile data connection?
Click to expand...
Click to collapse
I am in search of a similer thing.
Is it possible with port forwarding in adb ?
[email protected] said:
I am in search of a similer thing.
Is it possible with port forwarding in adb ?
Click to expand...
Click to collapse
Yes, it is possible. But 1st you must make sure your mobile operator is not blocking your connections.
Most data only SIM cards will not block connection, but only few operators allow connection to any SIM cards ( voice + data).
If you can ping your phone IP address while it is on 3g or 4g then you should be able to connect, some operators even block pinging but still allow the ADB connection.
1. connect your phone to a pc with usb
2. make sure it is visible by typing "adb devices"
3. type "adb tcpip 5555" to set up forwarding
4. once your phone is connected to mobile data (3g or 4g) go to settings -> about phone -> status -> IP address
5. from laptop.type "adb connect ip_addres:5555"
Have you tested this method on any network?
[email protected] said:
Have you tested this method on any network?
Click to expand...
Click to collapse
In Croatia, on Tele2 it works on both (voice + data) and data only cards, you are able to ping them both.
On Vip-net it works only on data-only cards and your are not able to ping them.
Also, if you are working inside a company network, the company firewall might block the connection
kuisma said:
You can set service.adb.tcp.port=5555 in /default.prop or maybe /system/build.prop. But this isn't such a great idea, since it leaves you phone open to everybody wanting to gain shell access to it over the net.
And you don't need "adb kill-server" above. It's the devices adb you are restarting, not the one on your computer.
Click to expand...
Click to collapse
I know it is really late to be saying this, but...
What a lot of people do when they need to open a port that is well-known, much like the SSH default port 22, is set a different port. Instead of 5555, use 7777 or something entirely different. It is much like a 4 digit passcode.
twistedumbrella said:
I know it is really late to be saying this, but...
What a lot of people do when they need to open a port that is well-known, much like the SSH default port 22, is set a different port. Instead of 5555, use 7777 or something entirely different. It is much like a 4 digit passcode.
Click to expand...
Click to collapse
Why not using a five digit passcode like 51423? Afaik you may use any port > 4096 and < 65536. The first 4096 are privileged ports...
guest4711 said:
Why not using a five digit passcode like 51423? Afaik you may use any port > 4096 and < 65536. The first 4096 are privileged ports...
Click to expand...
Click to collapse
Who said you couldn't?
Use any port number not already in use, but any known default assignment will defeat the purpose of avoiding intrusion. The point was that you aren't limited to 5555 exclusively.
Is it possible to target device to listen to port over wifi, without first connecting via USB?
omg no. please do NOT think that using a random port changes anything about security. I assure you it does not.
Turning off USB Debugging when its not in use seems to shut down access to 5555 - wouldn't that suffice from a security perspective? (only have USB Debugging on when you want to do ADB)
kuisma said:
You can set service.adb.tcp.port=5555 in /default.prop or maybe /system/build.prop. But this isn't such a great idea, since it leaves you phone open to everybody wanting to gain shell access to it over the net.
And you don't need "adb kill-server" above. It's the devices adb you are restarting, not the one on your computer.
Click to expand...
Click to collapse
hello! newbie here, can you please explain what is this "/default.prop or maybe /system/build.prop" Thank you
If I set this up in either build.prop or default.prop in a custom ROM, it works fine.
If I set this up in a stock MIUI ROM, it results in a bootloop, every single time.
I'm trying to figure out how to run adb tcpip 5555 in either post-fs or service.d for Magisk. The .sh script is given the correct execute permission and seems to run fine, but it doesn't actually set adb tcpip 5555 to enabled....
I just want to thank everyone for writing this thread way back in 2012, as we're STILL making good use of this information now, in 2022, when Android 11 (and up) has adb Wireless debugging options inside of Developer options... (no USB needed!).
(PSA) Using the new Android 12 TILE for 'Developer options' 'Wireless debugging' to establish adb connection over Wi-Fi without USB
I know it's been a while, but I find myself in need of adding this
Code:
service.adb.tcp.port=5555
line to build.prop on my unrooted Pixel 7 Pro. Here are some wild thoughts, as I am not an expert in rooting/unrooting:
With the unrooted phone, say I download the latest Pixel 7 Pro factory image and tinker with it, namely make the requisite change in build.prop, repackage the whole thing as a modified image, and then flash it onto my (unrooted) phone. Will that work? Or does the flashing process check the checksum before flashing?
Root the phone, make the requisite change in build.prop, and then un-root it back. Will this work? Or does the un-rooting process mess everything up, and destroy all the changes I made? (Mind you, I have no idea how un-rooting works, so please bear with me.)

How to debugging Android Device with WIFI connection

You wanna debug your Android device, but have not usb cable on hand.
Don't worry, you can still connect your device through WIFI if your PC and Android device are on the same LAN.
Following the steps:
1. Ensure the debuging port of Android Devices. You may use command "adb shell setprop service.adb.tcp.port 5553" to set the port to be 5553. The default port is 5555.
2. Find out the IP address of Android Device. For examble, 192.168.1.107
3. On your PC, use the command "adb connect 192.168.1.107:5553"
4. After connected, you may see the devices' list by using command "adb devices"

[TUT] ADB over WI-FI

ADB over Wi-Fi​Some of us might like to connect the device over WiFi for debugging, instead of using the data cable. Here's the required tutorial to do so
Requirements
1. Android device (duh!!!)
2. ADB in the computer (again duh!!!)
3. Root privileges
4. Terminal emulator (download from here)​
Let's begin then​Open terminal emulator on your device. Enter the following code
Code:
su [color="red"]Grant superuser here[/color]
setprop service.adb.tcp.port 5555 [color="red"]Can be anything else[/color]
stop adbd
start adbd
Check it with this
Code:
getprop service.adb.tcp.port
It will return 5555 or the number you entered in the above code​
Enter the following code on your computer in command prompt or shell
Code:
adb connect 192.168.0.151
Instead of 192.168.0.151, enter your device IP address​
To make your device listen on USB again, just restart the device. And enter the code on your computer
Code:
adb usb
I would definitely use the USB cable to push large files or even small files that you really don't want to risk corrupting (partition images you plan on dding, etc).
Very importantly, keep in mind, when your phone is listening for adb via WiFi, it's wide open... anybody that has adb installed and knows your device's IP address can access it without a password. Again, a simple reboot will turn it off though.​
Credits
JeepFreak for this post in the One X forum​
Reserved
Reserved for app​
I want to thank the OP, however belatedly, for writing these root instructions for users to connect their PC and phone via adb over Wi-Fi without USB cables being involved.
As the OP is well aware, non-rooted Android 10 and below allowed wireless adb connections AFTER a USB connection was first established (adb start-server && adb tcpip 5555 && adb connect [IP]:5555), but that changed (for the better) in Android 11 and above with the new new Developer options Wireless debugging random port assignments (adb connect [IP]:[PORT] or adb pair [IP]:[PORT] [PIN]) such that the adb wireless connection never needs USB cable ever again.
Given Android 11 allows Developer options Wireless debugging via a random port, and Android 12 new Developer options Wireless debugging allows that to be accessed even easier with a new Developer options Wireless debugging tile, the only thing missing is a way to get, after the fact, the random port assignment that Android uses for the adb wireless connection to your PC.
Some related threads for reference might be...
[adb,scrcpy,vysor] What ports does Android 12 randomly set when Wi-Fi connecting via Wireless debugging adb "pair" or "connect" commands?
(PSA) Using the new Android 12 TILE for 'Developer options' 'Wireless debugging' to establish adb connection over Wi-Fi without USB
What's the difference between Windows/Android adb "connect" versus adb "pair" when mirroring Android 12 over Wi-Fi onto a Windows PC?
The only question that's missing an answer preventing a perfect completely Wi-Fi automatic solution is...
Does anyone know how to obtain that random Android port address from the PC?

[Q] ADB only over wIFI no USB

Hello!
I am trying to find a way that I can only communicate over wifi with the adb on my device. So that for example if someone plugs in an USB cable to his pc, he should not be able to see my device as adb device. The only way to do something with adb should be over wify.
Is there any way to do that, or is the usb adb always on if adb is activated ?
For anyone finding this thread in the future (like I just did looking for solutions), as of about Android 11 and up, adb works over wi-fi (without USB) on non-rooted Android phones via Developer options Wireless debugging switches.

Categories

Resources