Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adb over Wi-Fi (Android 11+) on Windows: how to keep a fixed port or connect automatically?

The wireless adb connection works fine on my Android 11 phone + Windows workstation.

But it's not convenient, as every time the phone Wifi disconnects/reconnects, I have to:

  1. Turn on wireless debugging in Android settings.
  2. Take note of the port number XXXXX, which changes every time!
  3. Run adb connect 192.168.1.10:XXXXX on the computer.

Is there a way to skip step 2, by either:

  • making the port fixed?
  • making Windows automatically detect the phone on the new port? (documentation seems to imply that step 2 and 3 are not needed on MacOS, once the pairing is done, I wonder how this works)
like image 696
Sébastien Avatar asked Feb 01 '21 11:02

Sébastien


People also ask

Can you ADB over WIFI?

If you are an Android developer, I am 100% sure you might already be frustrated with debugging your App with ADB while being connected through a USB cable. If you didn't know already, you can connect to your Android Device with ADB over Wifi.

What port does ADB listen to?

When the server starts, it binds to local TCP port 5037 and listens for commands sent from adb clients—all adb clients use port 5037 to communicate with the adb server. As shown, the emulator connected to adb on port 5555 is the same as the emulator whose console listens on port 5554.


2 Answers

You can make the port fixed until reboot by adb tcpip

After pairing and connecting with the dynamic port

try adb tcpip 4444

then you can use adb connect ip:4444 until reboot (ya after reboot you've to connect with dynamic port and set tcpip to 4444 again)

like image 179
Edward Kenway Avatar answered Sep 23 '22 06:09

Edward Kenway


You can dynamically get port using nmap and connect to it.

here is my solution

adb connect <device_ip>:$(nmap $IP -p 37000-44000 | awk "/\/tcp/" | cut -d/ -f1)

Scanning only ports 37000-44000 is sufficient Also wireless debugging should be enabled and device needs to unlocked during nmap scan. Run it again if the nmap doesn't find the port first time.

I have added the command to an alias so it is easy to run
ex:
alias adbw='adb connect 192.168.0.7:$(nmap $IP -p 37000-44000 | awk "/\/tcp/" | cut -d/ -f1)'

To connect next time:

  1. Unlock Device
  2. Enable Wireless debugging (you can add it to status bar icons)
  3. run adbw if alias set.

Ex Output:
connected to 192.168.0.7:38395

like image 44
Build3r Avatar answered Sep 22 '22 06:09

Build3r