[PYTHON SCRIPT][WINDOWS]Start scrcpy over Wi-Fi - Android Software/Hacking General [Developers Only]

This script is for non rooted phones, as on rooted ones TCP listening for adb can be configured on the device and it doesn't need to be plugged to the USB beforehand, meanwhile on un-rooted ones it should be apparently done after every phone reset. I've made this script so I don't have to manually enter commands every time eye wish to start scrcpy after a phone reset. The script also minimizes which also hides the scrcpy command line afterwards, but can also be hidden.
What it does:
- Minimizes the window
- Issues "ifconfig" to the device to get its IP.
- Enables port listening and connects to the device over WiFi
- Waits a bit
- Starts scrcpy.
Usage:
- Connect the phone
- Allow the dialog on the phone //if asked
- Open the script
- Allow the dialog on the phone //if asked
- You can disconnect the device
- Should be all.
The script has to be placed in the scrcpy's directory to work, and should only work correctly with one device connected.
To hide the window you can change the following line:
Code:
ctypes.WinDLL('user32').ShowWindow(ctypes.WinDLL('kernel32').GetConsoleWindow(),6)
to :
ctypes.WinDLL('user32').ShowWindow(ctypes.WinDLL('kernel32').GetConsoleWindow(),0)
and if you wish to run scrpy with some arguments you can do so by editing the following line:
Code:
os.system("scrcpy -s "+AyyyP+":4774")
where you can either add other arguments befor the "-s" part or after the ":4774" like so:
os.system("scrcpy -m 720 -s "+AyyyP+":4774")
or so:
os.system("scrcpy -s "+AyyyP+":4774 -m 720")
the changes should be doable in almost any text editor. Scrcpy attributes can be currently found here.
Also python 3.x has to be installed on the PC which should be obtainable here.
Sidenote: File is located in a .zip so I was able to upload it, just extract it beforehand.
If you have any questions feel free to ask .

Reserved.

Thank you for this python scrcpy script on behalf of everyone who loves scrcpy/sndcpy mirroring onto the PC as I do, where I'd like to take the developer up on his offer of:
If you have any questions feel free to ask
Click to expand...
Click to collapse
As most people know, Android 10 and below allowed wireless adb connections AFTER a USB connection was first established (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.
[adb,scrcpy,vysor] What ports does Android 12 randomly set when Wi-Fi connecting via Wireless debugging adb "pair" or "connect" commands?
Does anyone know how to obtain that random Android port address from the PC?

I am asking for detailed instructions on how to install it on the galaxy s22U? I can't handle it on my own.

Related

How to connect two android devices over USB

First, why:
I own two Coby Kyros tablets that I am using as a part-time car headrest entertainment system. Heck, they are so cheap, buying a dedicated car video just does not make sense.
Tablets work great for that purpose, great resolution (for a car), have games and music. There is only one piece that is missing, simultaneous video playback on both tablets.
Getting this working presents two challenges:
* A fast, stable, always ON connection between the tablets.
* A master/slave video playback software, either streaming or syncing
Glad to report, I've solved the first issue, that I'll describe here. Be warned this is not for the faint of hart and right now is fully manual. If you find it helpful I might work on automating the link.
Tested on Froyo. At least one device has to be rooted and support the USB Host mode.
Now, how:
The idea is simple - use the android debugging bridge to forward TCP ports between two systems over USB. If you do have USB tethering enabled on at least one device (I did not) you could use RNDIS to route all traffic, not just specific ports, over USB.
1. Pick a tablet to be the slave. It must be rooted. Get the adb client compiled for android from here, upload it to the slave /system/xbin ("adb push ...") and make executable (adb shell chmod 755...). Get ConnectBot from the market to access its console.
2. Put the slave into the USB Host mode, disable USB debugging on it. Put the master into the USB device mode and enable USB debugging.
3. Connect the master and the slave using a miniUSB-USBfemale and USBmale-miniUSB combination, a USB hub (make sure it is a high-speed one) or a miniUSBmale-miniUSBmale cord.
4. Now the tough part, typing shell commands on the tablet. You can make it a bit easier by using a USB hub and connecting a keyboard and a mouse together with the other tablet to the slave.
On the slave start ConnectBot for the localhost and type the following
Code:
less /proc/bus/usb/devices
Look for your master's devices BUS# and DEV#. Record both. Note, these numbers change when you re-plug USB.
Now, on the slave:
Code:
su
mkdir -p /dev/bus/usb/001/
ln -sf /proc/bus/usb/[BUS#]/[Dev#] /dev/bus/usb/001/001
5. Test. On the slave run 'adb devices'. It should show your master in the list.
6. Forward slave ports to the master as needed. Run 'adb forward tcp:123 tcp:234'. Now you can use localhost:123 on the slave to reach out to the master port 234 over USB.
If your kernel is RNDIS enabled you could route all network connections over the usb0 interface, essentially creating a one-to-one network. Stock Kyros unfortunately does not support RNDIS so I've not tested it.
The ADB USB speed is not bad, averaging 2.5MB/sec after protocol overhead.
I did some research on the second issue, went several routes (mplayer, VLC and UPNP) and, sadly, found nothing that currently works. If you know of any working video source/sink pair or a sync peer for android, let me know.
sicvolo said:
Tested on Froyo. At least one device has to be rooted and support the USB Host mode.
Click to expand...
Click to collapse
Is there a guide on getting USB Host Mode to work on this device or if there isn't could you write one?
I have two Galaxy S3. I went through steps 1-3, all fine. But in step 4, there is no '/proc/bus/usb/devices'; there are only '/proc/bus/input' and '/proc/bus/input/devices'.
Is there any other method to get dev# and bus#? Thanks.

samsung smart swith for ubuntu?

hello, i am usning ubuntu. is there any desktop software for managing my tablet, like samsung smart switch on windows for ubuntu?
Scrcpy, adb, vnc
d9867eb said:
hello, i am usning ubuntu. is there any desktop software for managing my tablet, like samsung smart switch on windows for ubuntu?
Click to expand...
Click to collapse
There are a lot of choices to choose from if you want to manage your tablet with Ubuntu. However, there are different methods for different programs and you get different functions out of each. I'll compile a quick list for you, but without a little more specificity, I don't know what you mean by "manage".
1) VirtualBox - You can always use VirtualBox to run Windows and use that to install Samsung Kies/Smart Manager/etc.
apt install virtualbox
2) ADB - (USB Debugging must be enabled). Android Debug Bridge is a command-line based program to control different things on your device. To start, go to Settings - About Phone. Depending on your version of android it could be in "Software" or something along those lines but find "Build Number" and tap on it until it says "Developer Settings enabled". Afterward, go back to Settings and find the Developer menu. Turn it on first (there should be a box/slider/something on the top or in the menu) and go to USB Debugging. If it is grey'ed out and you can not turn it on, try turning off and on the developer settings. Once USB Debugging is enabled plug your device into the computer. The phone will ask a question about trusting the computer, press yes. Now, launch a terminal and type "adb devices". As long as only one device is plugged into your computer, and as long as the device is listed as "device" and not "offline" "unauthorized" or something like that, you can issue it commands! For more info on ADB, just google adb commands. "adb shell" gives you direct access to the /bin/sh shell in android. From there you can run commands directly through your tablet. Last note on this: 'adb tcpip 5555' restarts the adbd program on the tablet to listen for connections over the LAN/WAN/whatever it is connected to. To connect from the computer, type "adb connect <ip>" where <ip> is the tablet's IP address.
apt install android-tools-adb
3) scrcpy: Scrcpy is a program, written in java, that will use adb to display the screen of your android device in Ubuntu/anything that runs java. You can also click/type through it, allowing you to control it remotely. A word of warning: I don't know why, but my first few times trying to install this program were a major fail. I eventually got it, and it works pretty good, but it wasn't easy.
google: scrcpy (it's a github link)
4) VNC: You can install something like a VNC (Virtual Network Client) server or RDP (Remote Desktop Procedure) server on the tablet, and connect to it with tight/tiger vnc. Note: Device may have to be rooted for this, and, from my experience, most VNC servers wont work right. However, this has worked for my Samsung tablet in the past (the screen it broken on it but the digi is okay. I cant use scrcpy because scrcpy requires Lollipop I think and it has Kit Kat). I think the app "DroidVNC Server" was what I used.
5) Check Play Store for "android remote manager"
6) nuntius/kali-rolling 0.2.0-5+b1 amd64
share notifications from Android phone or tablet via Bluetooth or LAN
NOTE: I didn't like this program, but feel free to give it a shot!
Hope this helps!

[Resolved] Remote (TCP/IP) ADB to Samsung S7 (herolte) with latest available stock ROM 8.0.0?

The solution is just one post below.
_____
Hello! Does anybody know how to remotely (TCP/IP) ADB connect to the Samsung S7? Other phones have an option to (temporarily) enable also remote ADB in the developer settings. However, I cannot find such an option on the S7 (with the latest available stock ROM 8.0.0). Thanks for sharing your hints.
PS:
Usually, when remote (TCP/IP) ADB is enabled, you can connect to the device (e.g. an Amazon Fire TV) from another device (e.g. your PC) with e.g. this:
Code:
local shell> adb connect fire-tv
connected to fire-tv:5555
local shell> adb shell
mantis:/ $
PPS and OT:
You can then use scrcpy to mirror your remote device on your local machine, navigate through it and even drop files there.
For Windows users: It's also available in the main scoop bucket.
Normally, you enable USB Debugging, connect your phone with USB, execute:
adb tcpip 5555
adb connect phone_ip:5555
But, in case of a broken port, you'll need root access, then execute the provided commands.
You can use any port you want, but for security reasons I advise you to use 5-digit port.
Perfect, thank you so much @Mohamedkam000
In order to enable search engines finding this solution, I have copied below the code from your screenshot (and put the note about the port number into <pointed brackets>:
Code:
su
setprop service.adb.tcp.port <port number, e.g. 5555>
stop adbd
start adbd
Port number 5555 is the standard for adbd, i.e. if one then connects to the device without explicitly providing a port number, it should be 5555; else, the port number has to be appended to the IP with a leading ":", like this:
Code:
connect <my-mobile-phone's-ip:my-mobile-phone's-port-number>
E.g.:
Code:
connect 192.168.178.99:223344
Or one can use the mobile's hostname, e.g.:
Code:
connect Samsung-S7:223344
If one has multiple devices connected via TCP/IP ADB, one can distinguish between them via the port number, see e.g.:
Code:
remote shell> adb devices
List of devices attached
samsung-s7:44444 device
samsung-s7:5555 device
Here I connected 2 times to the same mobile with 2 different port numbers (does not make much sense, but for the sake of an example).
Last but not least:
It seems that some Android mobiles have an option in the developer settings specifically to enable/disable remote (TCP/IP) ADB (besides the usual ADB via USB), while others (like the Samsung S7) do not have this option. In the latter case, the code kindly provided by @Mohamedkam000 does the same. Thanks once more - I have again learnt something.
PS:
If one does not need the remote ADB connection anymore, one should stop the adbd service on the mobile device (as root) with "stop adbd" as shown above (also for security reasons). So root seems to be required for this.
7wells said:
Perfect, thank you so much @Mohamedkam000
Last but not least:
It seems that some Android mobiles have an option in the developer settings specifically to enable/disable remote (TCP/IP) ADB (besides the usual ADB via USB), while others (like the Samsung S7) do not have this option. In the latter case, the code kindly provided by @Mohamedkam000 does the same. Thanks once more - I have again learnt something.
PS:
If one does not need the remote ADB connection anymore, one should stop the adbd service on the mobile device (as root) with "stop adbd" as shown above (also for security reasons). So root seems to be required for this.
Click to expand...
Click to collapse
You are welcome, mate.

PSA) Using the new Android 12 TILE for 'Developer options' 'Wireless debugging' to establish adb connection over Wi-Fi without USB

This is a PSA for those who mirror their Android phone onto Windows each day that there is a wonderfully convenient new TILE for Wireless debugging.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Android Wireless-debugging tile
That new Wireless-Debugging tile replaces this sequence of commands:
Settings > Developer options > Wireless debugging = on
But a lot of things turn that 'Wireless debugging' switch off on you!
Boot turns W/L debug off
It's not easy to find that new TILE though, where I found it here.
Settings > Developer options > Quick settings developer tiles
Wireless debugging = on
Which gets automatically turned off whenever your Wi-Fi is turned off
(so you're constantly turning it back on if you have Wi-Fi not set to turn on automatically & if auto-reconnect is also off for privacy reasons).
Allow wireless debugging
In summary, this new "developer options tile" for 'wireless debugging" is a great time saver as it's required to mirror Android over Wi-Fi without USB.
ScrCpy vs Vysor PC mirror
--
The background is for privacy I have my home router set to not broadcast the SSID (so as to keep it out of databases which don't respect the "_nomap" opt-out naming conventions and to prevent most phones from uploading it even to the servers that do respect the opt out naming conventions) and therefore, it's required for privacy to also set my Android Wi-Fi radio to not broadcast that SSID when I'm away from that home router (i.e., Android Wi-Fi setting for that specific SSID is set to not auto-reconnect).
Because of those two privacy options (one on the router, the other on the phone), whenever my phone disconnects from Wi-Fi (e.g., if I drive down the driveway away from my home router), the Wi-Fi on the phone also turns off, which is exactly what I want to happen.
However, when I return home, the Wi-Fi on the phone has to be manually turned on, and so does 'Wireless debugging' in 'Developer options' because you need to be connected to a Wi-Fi access point and you need to have Wi-Fi Debugging turned on in order to establish a Wi-Fi adb connection over Windows to mirror the phone display, keyboard, mouse, and clipboard onto the PC (without ever needing to use a USB cable, even only momentarily).
Given that background, I was seeking a simpler way to turn on Androiud 'Wireless debugging', which turns out to be adding this 'Wireless debuggon = on/off' goggle tile to your Android swipe-down menu.
The use model is when you reboot the PC or when you return home, you swipe down on Android 12 to tap both the Wi-Fi and 'Wireless debugging' toggling tiles, and then you can mirror your phone onto your PC using the following adb commands on the phone and PC (listed in step-by-step order although there are many ways to accomplish the same task - this is only one of them)
(Phone) Swipe down & manually turn on Wi-Fi via the "Wi-Fi" TILE
(Phone) Longpress on that 'Wi-Fi' TILE to connect to a previously saved AP
(Phone) Tap to toggle the 'Wireless debugging' Android TILE on.
(PC) C:\> adb kill-server (optional, to set a known starting point)
(PC) C:\> ping 192.168.0.2 (optional, to check if you're on the LAN)
(PC) C:\> adb devices
(PC) C:\> vysor.exe (this will bring up the Vysor GUI to mirror Android)
Note prior to Android 11, to establish that adb connection over Wi-Fi, you first had to use a USB cable to set up tcpip on port 5555 and _then_ after establishing a link to adb, you could disconnect USB to use it on Wi-Fi.
C:\> ping 192.168.0.2 (optional to test you're on the LAN over Wi-Fi)
C:\> adb kill-server (optional to start at a known starting point)
C:\> adb tcpip 5555
C:\> adb connect 192.168.0.2:5555 (port is optional)
C:\> adb devices (optional to see what devices are connected over adb)
But the situation I'm describing does _not_ need to use that USB cable.
Great explanation THANKS!!!
One silly issue, where you can have a lead for me:
every time Wireless Debug reconnects it will change randomly IPort number
I use SCRCPY which is similar to VYSOR... but completely free...
it will not be able to reconnect not knowing what port to call, and having lost the previous one.
Using SCRCPY I'm mirroring two static androids on USB and that's fine,
but the issue is with the other two mobile androids ( main & backup ) that I have to connect wireless because they are moving with me.
This is part of the .BAT for my main cell> POCO F3
::Go wireless instead
:Wireless
ADB connect 10.0.1.103:38277
scrcpy.exe --window-x 1500 --window-y 45 -s 10.0.1.103:38277
Click to expand...
Click to collapse
This is POCO F3 W. D. screen with the ver changing port number
.... BAT results are the same with the wrong port and without a port number
By default without a Port Number,
it will try only the standard port:55555 and as per the previous Port:38227 it will not be authorized to use it !!!
Is there a way to set fixed that Port number?
I have to manually look at it and then change it in my .BAT.
Even a simpler roundabout that allows me to get back my androids automatically on the PC will be fine !!!
AlainCh2 said:
every time Wireless Debug reconnects it will change randomly IP port number
Click to expand...
Click to collapse
I know. I know. It happens to me also.
It's even worse in some ways in that BOTH ports change.
That is, every once in a while the random port changes for the adb "connect" command:
C:\> adb connect 192.168.0.2:12345
And, at the same time, the random port (which is a DIFFERENT port!) also changes for the adb "pair" command (as does the 6-digit PIN).
C:\> adb pair 192.168.0.2:54321 123456
Sometimes the port stays the same for days, sometimes it changes. I haven't tested yet what circumstances change that port, but I agree with you that it happens a lot.
AlainCh2 said:
I use SCRCPY which is similar to VYSOR... but completely free...
it will not be able to reconnect not knowing what port to call, and having lost the previous one.
Click to expand...
Click to collapse
I use both scrcpy and vysor (both of which are free, but vysor has some non-free stuff that I don't need).
Interestingly Vysor "says" it won't do pure wireless without paying for it but that isn't true - both scrcpy & vysor work completely wirelessly.
Vysor won't give you the good resolution without paying for it while scrcpy will give you better resolution all the time.
They're essentially the same (as far as I can tell anyway)... where I had to write a script to make scrcpy work without the console though (whereas vysor works without the console without modification).
Certainly Vysor is SLOWER than scrcpy on startup, where scrcpy is almost immediate and nothing needs to be put onto Android, but with Vysor, it MUST install some temporary vysor.apk each time you run it, but once they're both up and running, the speed is indistinguishable (as far as I can tell).
The one thing Vysor seems to do better than scrcpy is it seems to figure out better what port adb is currently on - but I don't know how Vysor does it - and - worse - Vysor doesn't do it correctly every time.
It's frustrating - which is why I AGREE with you that if we could somehow lock the port down on Android - that would solve the problem - or - if we could figure out using a Windows command what the current port is on Android - that would also solve the problem.
We need help from Windows/Android experts!
AlainCh2 said:
By default without a Port Number,
it will try only the standard port:55555 and as per the previous Port:38227 it will not be authorized to use it !!!
Click to expand...
Click to collapse
I'm with you about the port number having to be put into the batch file, where I have a batch file for scrcpy that no longer requires the port but I have to establish the adb connection first unfortunately.
AlainCh2 said:
Is there a way to set fixed that Port number?
I have to manually look at it and then change it in my .BAT.
Click to expand...
Click to collapse
I have the same problem that the port keeps changing.
I have the same question as you do, but I was approaching it from the OTHER angle.
That is, the batch file can ascertain what the port number is.
That's possible - but I don't know Windows well enough to be successful all the time. Sigh.
AlainCh2 said:
Even a simpler roundabout that allows me to get back my androids automatically on the PC will be fine !!!
Click to expand...
Click to collapse
I think there are two approaches to a solution.
1. Try to keep the port static, or,
2. Try to figure out the port (after the fact) in the batch file.
I've been working on the latter using these Windows commands.
C:\> netstat -ano -p tcp | findstr "192.168.0.2"
C:\> adb shell "ifconfig|grep -A 1 wlan0|tail -n 1|cut -f2 -d:|cut -f1 -d' '"
C:\> adb mdns services
C:\> nmap 192.168.0.2
But I need help in how to figure out the port from Windows.
Once we figure out the port, we can feed it to the batch files.
Wow, interesting!
Would I've been in my glorious years my brain would have helped a, lot.
Now I'll try to do my best.
Differences in our network management:
Cell side
>All my cell's IP are static by router
>All my cell have USB Debugging enabled
>All my cell have Wireless enabled :: Unless the phone disable it
LAN side
>My LAN is always on > All home is covered but 2mt of south balcony
>I lose Wireless When I leave Home :: When I go on South Balcony
__________________________________
My full script is quite simple and contain REM'd the debug instructions
Code:
::@echo on
@echo off
powershell -window hidden -command ""
:: Poco F3 - PF3s - M2012K11AG
:: --serial a7ff2388
:: --serial 10.0.1.103:38277 37751 39685 37293
cd /d "D:\D_\ScrCpy - ScreenCopy\"
:Top
::Start "trying a go on USB - WIRED"
scrcpy.exe --window-x 1500 --window-y 45 -s a7ff2388
:: Check if the wire is connected
:: if the exit code is >= 1, no phone on wire
if errorlevel 1 TimeOut /t 4 /nobreak
::Goto Top
::Go wireless instead
:Wireless
ADB connect 10.0.1.103:37293
scrcpy.exe --window-x 1500 --window-y 45 -s 10.0.1.103:37293
::::: I Must use as -SERIAL the IP and not the ADB serial "a7ff2388" >no reason given
::Exit
::Pause
::Back on Wire
Goto Top
Let's see what I've got so far:
#Port number
the number change every time :: IP Reconnect :: Wifi Reconnect :: no other reason
From you I get that ...
We can in some way divine the port number
With netstat / ipconfig using the fixed cell Ip
But so far it seems No cells are connected to the LAN
103 = PocoF3
109 = P9 Lite
110 = HonorW10
105 = N5T
065 = T365
for sure I'm doing something wrong using this command: "netstat -ano -p tcp"
I checked as well "netstat -ano -q"
For sure PF3s is now connected on USB to the PC, but also sure it should appear on LAN as well
The router see all of them
When I come back home, it seems that the cell have not reset the Wireless debugging
but that's not true !!!
When I enable it, it will assign a new port...
... will it announce on the network as "port OPEN xyyyzxx"
... or it will be used just LISTENING to check the connect request??
BTW : I never used the pairing method you use.
While I know that you can look at all the TCP connections related to your IP
I have a big doubt that W10 would see the full Lan IP_Ports from its own interface.
...
..... digging down on that.
.... Mumble ... mumble .. mumble...
YEEEESSSSSS!!!
My brain became sluggish but it still work - in a way
Netstat and IPConfig works only from inside to any outward connection/adapter,
and they cannot go looking out.
You have to use a different command "PORTQRY" to be downloaded from Microsoft itself:
"To view the TCP/UDP open port state of a remote host, type “portqry.exe –n [hostname/IP]” where [hostname/IP] is replaced with the hostname or IP address of the remote host. You can also specify to scan for a particular port using the “-e [port_number]” parameter, a particular range of ports using the “-r [start_range:end_range]” parameter, or a group of ports in a particular order using the “-o [port1, port2, port3]” parameter."
Last thing to do:
Learn how to use "portqry.exe"
____________________________________________
Here we go from my observations:
Assuming the random port being in the range 30k-44k, I need to check who's listening.
I get the identification string response > using the known port I checked in Android's PF3s settings.
But the process takes several minutes up to half an hour...
NP this is the first screenshot... just in case you read it before I'm back online.
#@#!!!!!
ok, it took 12 minutes to check 138 ports !!!
I tested that on a shorter range_
Seems I cannot delimit correctly the FINDSTR "xxxxxxxxxx"
It's a good night for me !!!
<2022-08-02 01:23:41>this post took 3hours 11minutes 33seconds - using a very large amount of my BRAIN<
:-D
Wow. That's a lot to digest. You did great work!
Really great work!
Thanks for all that work on behalf of me and you and everyone!
I will have to take HOURS to go through all the wonderful work you did, particularly in finding that "portqry.exe" command that maybe can tell us what port the Android phone recently switched to (since that's the root of the problem!).
BTW, regarding the "adb connect" versus "adb pair", I think the difference is just in encryption (connect apparently isn't encrypted), where if that's the case, it doesn't matter which you use otherwise.
However, I could be wrong, so I had asked a while ago here, but nobody answered the question unfortunately.
What's the difference between Windows/Android adb "connect" versus adb "pair" when mirroring Android 12 over Wi-Fi onto a Windows PC?
Since you posted your script, here is my scrcpy script which gets rid of the console (but adb has to already be connected for it to work without the port number - which is how I use it most myself).
Code:
@echo off
REM C:\app\editor\android\scrcpy\showwin.bat
REM adb mdns services
REM List of discovered mdns services
REM netstat -ano -p tcp | findstr "192.168.1.10"
REM TCP 192.168.1.27:15919 192.168.1.10:41913 ESTABLISHED 7904
REM
cd /d "c:\app\editor\android\scrcpy"
certutil -f -decode %~f0 showwin.exe>nul
REM Port 5555 was needed when you established adb connections over USB
REM And then you disconnected the USB cable to subsequently work on Wi-Fi
REM But as of Android 11 or 12, you can establish the connection over Wi-Fi
REM But that "Developer option" "Wireless debugging" port is assigned by Android!
REM So you have to get it on Android or on Windows to know what it is
REM adb connect 192.168.1.10:5555
REM You can get the current port from the following command
REM c:\> netstat -ano -p tcp | findstr "192.168.1.10"
REM
REM maybe we do NOT need this command after all???
REM adb connect 192.168.1.10:41913
:: now we hide console window
showwin.exe 0
REM scrcpy --always-on-top --tcpip=192.168.1.10:5555
REM Maybe we can then remove the IP:PORT after all???
REM scrcpy --always-on-top --tcpip=192.168.1.10:41913
REM We don't really need --always-on-top after all???
REM scrcpy --always-on-top
scrcpy
:: after scrcpy is closed we show console window again
showwin.exe 5
del showwin.exe
goto :eof
-----BEGIN CERTIFICATE-----
TVpgAQEAAAAEAAAA//8AAGABAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAoAAAAA4fug4AtAnNIbgBTM0hTmljZSB0byBtZWV0IHNvbWVi
b2R5IHdobyBpcyBzdGlsbCB1c2luZyBET1MsDQpidXQgdGhpcyBwcm9ncmFtIHJl
cXVpcmVzIFdpbjMyLg0KJFBFAABMAQEAUHmlNgAAAAAAAAAA4AAPAQsBBQwAAgAA
AAAAAAAAAADIEAAAABAAAAAgAAAAAEAAABAAAAACAAAFAAAAAAAAAAQAAAAAAAAA
ACAAAAACAAAAAAAAAwAAAAAAEAAAEAAAAAAQAAAQAAAAAAAAEAAAAAAAAAAAAAAA
GBAAADwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAYAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALnRleHQAAAAmAQAAABAAAAACAAAAAgAA
AAAAAAAAAAAAAAAAIAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABoEAAAAAAAAJQQAACmEAAA
uhAAAAAAAABgEAAAAAAAAAAAAABUEAAAABAAAIQQAAAAAAAAAAAAAHYQAAAIEAAA
AAAAAAAAAAAAAAAAAAAAAAAAAABVU0VSMzIuZGxsAABoEAAAAAAAAAAAU2hvd1dp
bmRvdwAAS0VSTkVMMzIuZGxsAACUEAAAphAAALoQAAAAAAAAAABHZXRDb21tYW5k
TGluZUEAAABHZXRDb25zb2xlV2luZG93AAAAAEV4aXRQcm9jZXNzAP8VCBBAADHS
SECAOAB0EYA4InUC99IJ0nXvgDggdepAMfa9BQAAAA+2EEAI0nQTgOowcvOA+gl3
7mv2CgHWMe3r5QntdAKJ7v8VDBBAAFZQ/xUAEEAAagD/FRAQQAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAA==
-----END CERTIFICATE-----
In addition, if you run any free WebDAV server, you can mount your entire Android phone (even most of the read-only root partition!) as a drive letter onto Windows without having to use FTPUse to do it.
C:\> net use Z: \\[email protected]\DavWWWRoot /USER:foo bar & net use Y: \\[email protected]\DavWWWRoot /USER:foo bar
I had to use TWO free webdav servers though... one for the internal sdcard and one for the external sdcard - each on a different port - as nobody solved the problem I posed a while ago over here asking how to do it with just one webdav server.
Can you mount BOTH Android internal & external storage onto Windows as a drive letter over Wi-Fi using a SINGLE WebDAV server?
AlainCh2 said:
Last thing to do:
Learn how to use "portqry.exe"
Click to expand...
Click to collapse
This morning I downloaded the Microsoft PortQry command where I place what I did below to help save time for others who can read this instead of doing it to get an idea of what it is & how it installs.
1. Googling, I found the canonical location of the Microsoft command.
PortQry Command Line Port Scanner Version 2.0​<https://www.microsoft.com/en-us/download/details.aspx?id=17148>​
2. I downloaded it (where I'm not sure if this URL is static or dynamic):
<https://download.microsoft.com/download/0/d/9/0d9d81cf-4ef2-4aa5-8cea-95a935ee09c9/PortQryV2.exe>​Date: 20220802​Name: PortQryV2.exe​Size: 151112 bytes (147 KiB)​SHA256: 6471C5190A99E3D1F337FCFEF1FC410E8D487B66E093F924700E186CBD398DC0​
Doubleclicking on the file above asks to unzip it.
It wants to go by default into c:\PortQryV2​Instead I put it where it belongs at c:\app\network\portqry​ (Note that I decide where things belong... not a billion different developers who don't have a common vision.)​
Resulting in:
Date: 20220802​Name: PortQry.exe​Size: 143360 bytes (140 KiB)​SHA256: FB6CEBADD49D202C8C7B5CDD641BD16AAC8258429E8FACE365A94BD32E253B00​
Then I downloaded the port query user interface.
PortQryUI - User Interface for the PortQry Command Line Port Scanner​<https://www.microsoft.com/en-us/download/details.aspx?id=24009>​<https://download.microsoft.com/download/3/f/4/3f4c6a54-65f0-4164-bdec-a3411ba24d3a/PortQryUI.exe>​
Resulting in:
Date: 20220802​Name: PortQryUI.exe​Size: 217160 bytes (212 KiB)​SHA256: D462DD1AD77B37E9E681F9A779550B3918AF4925EC6F3D0014E6880B69B98126​
Doubleclicking on the file above asks to unzip it.
It wants to go by default into C:\PortQryUI​Instead I put it where it belongs at C:\app\network\portqry​ (Note that I decide where things belong... not a billion different developers who don't have a common vision.)​
Date: 20220802​Name: portqueryui.exe​Size: 70656 bytes (69 KiB)​SHA256: DCD38075F8D594763A498FE884A85394DB66BB604A0A1E6E6AC823923ADD910D​
I doubleclick portqueryui.exe and a GUI comes up & I type the IP address of the phone (sans port) and then the MS Port Query GUI runs a scan of the phone's IP address, which, let's face it, takes a very long time to complete (at least with the defaults it does).
BTW, I've noticed the ports used by adb seem to always be in the same range of 3#### and 4#### so maybe we can save some time by scanning only those ports as explained here.
How To: Mastering PortQry.exe​<https://techgenix.com/portqry-howto/>​​Specifically:​C:\> portqry -n 192.168.0.2 -r 30000:40000​​And, well, um, er... it takes FOREVER and reports a lot of "NOT LISTENING" lines which are useless to us for our purpose... so I see (belatedly) now why you needed the "find string" syntax to find just the ports that adb is using!​​If we knew more about adb, maybe we could query more specifically the type of ports adb uses (e.g., mdns services)?​
AlainCh2 said:
Differences in our network management:
Cell side
>All my cell's IP are static by router
>All my cell have USB Debugging enabled
>All my cell have Wireless enabled :: Unless the phone disable it
LAN side
>My LAN is always on > All home is covered but 2mt of south balcony
>I lose Wireless When I leave Home :: When I go on South Balcony
Click to expand...
Click to collapse
As I explained over here a while ago, most of us do a bunch of things that provide us Wi-Fi privacy that we have to keep in mind, where what I do is somewhat similar to what you do, as shown below.
My home SSID/passphrase do not contain identifying words
So as to keep out of WPA2/PSK butterfly/rainbow hash tables
While at the same time they are as unique as I can make them
And I change them every once in a while for obvious reasons
Where the SSID has "_nomap" (it used to also have "_optout_")
But that doesn't stop WiGle/NetStumbler/Kismet/etc. uploads
And that doesn't stop passwerby from uploading to Google/Mozilla servers either!
Even as these well-behaved servers "say" they scrub this information
So that Google/Mozilla get it - but they don't publish it
Because you can be tracked if anyone knows your phone SSID
Simply by querying the public servers with any other known SSID
So I also turn off the broadcast of that SSID on my home router
Which means the cell phone has to remember the SSID
But the phone would "shout out" that SSID with AutoConnect
So I turn "AutoConnect=off" on the cell phone
So now, when I go down my driveway, it doesn't shout it out
In addition, I used to randomize the MAC by each SSID
Which meant that random BSSID was "reserved" on my router
And that the IP address was set to "static" on the phone
New in Android 12 Developer options, I can now randomize the phone's Wi-Fi MAC address on each and every connection
While still reserving the IP address on the home router
And, like you, every phone I get, the first thing I do is enable USB debugging (so I can recover from a smashed screen), yet, with Android 12, there's never a need for a USB cable anymore as everything it did is now rendered obsolete nowadays...
a. Many phones charge wirelessly nowadays​b. My phone is mirrored (sound/screen/keyboard/clipboard) over Wi-Fi to my PC (sndcpy,scrcpy,visor)​c. My unrooted phone is mounted as a drive letter onto Windows (Z: for the internal sdcard and Y: for the external sdcard)​​And, of course, there are a few things which are forbidden on my phone:
a. There will never be a mothership tracking account (not Google, not Samsung, not my Bank, nothing)​b. There will never be a way to pay for anything or to get money from anywhere​c. There will never be a log in to a mothership account (except, perhaps, email, when necessary)​
And, most radios are turned off by default, and only turned on when necessary and then turned off again...
a. Uploads of other people's Wi-Fi to Google servers are always permanently turned off
b. The GPS radio is off by default & location accuracy is always off
c. The NFC radio is turned off by default
d. The Bluetooth radio is turned off by default
e. Developer options Wireless debugging is on by default (but it turns off when the AP is no longer connected when I leave my driveway)
The only radios left on, by default are:
a. The cellular radio
b. The cellular data radio
And I have a few cellular and cellular data aps monitoring when I'm out of cellular calling/data range (but this isn't a privacy thing per se).
GalaxyA325G said:
BTW, I've noticed the ports used by adb seem to always be in the same range of 3#### and 4#### so maybe we can save some time by scanning only those ports as explained here.
How To: Mastering PortQry.exe<https://techgenix.com/portqry-howto/>Specifically:C:\> portqry -n 192.168.0.2 -r 30000:40000And, well, um, er... it takes FOREVER and reports a lot of "NOT LISTENING" lines which are useless to us for our purpose... so I see (belatedly) now why you needed the "find string" syntax to find just the ports that adb is using!If we knew more about adb, maybe we could query more specifically the type of ports adb uses (e.g., mdns services)?
Click to expand...
Click to collapse
I suppose you missed the last part of my message after "learn how to use" it
Range:
I checked it from the past reconnections: ports 30xxx to 44xxx
TIME:
It took me 20 minutes to do 138 ports
>>>but maybe ... sending to log instead of using cache... can be faster
SEARCH:
I showed the found string as well
_______________________
I've got the string to look at >> "e): LIST"
_______________________
°-°
The most difficult task is now up to you:
How to pass the found record to ADB & SCRCPY
String found = VAR1
>> ADB CONNECT IP:"VAR1"
>> SCRCPY ..... -s IP:"VAR1"
°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
Big issue is the time needed to connect the cell to the PC
> for the first time after you get home
For me, reconnecting it's twice a week in a normal situation, 'cause I'm normally locked in bed...
...but I imagine you and other people are in a different situation.
For me, it would be no problem at all, if under 1 hour,
provided that the .Bat will wait for the PocoF3
> xxx.103 to appear in LAN, before starting to look for the port.
This is why:
After a foraging boot, I enter the LAN while I'm parking the car downstairs.
Both Car and Cell connect nearly at the same time.
It will take some time ....
to climb 19 steps and getting upstairs, enter the home, arrange all the goods, then do the chores at hand
.... as much as 20 to 40 minutes or more will pass before I finally go to the PC and lay back onto the bed.
(usually forgetting somewhere the phone till it will ring - or I need for an SMS confirmation code, for instance)
I would have to rise and search - no matter how I feel
>>> that's the reason it's so useful for me to have it wireless on PC <<<<<
Even if it takes a long time I wouldn't probably even notice it,
if I'm not going straight to the PC, and in that case, I plug the cell in USB.
It's after that I may forget again, rise and search. So now I maniacally do Port's manually.
( unless I forget to do it the first time - start again from tiles zero )
I just came home and connected to scrcpy via adb over port 41703
(which I knew was the port from looking at the phone, but I WISH I could figure out that port from Windows!)
C:\> adb connect 192.168.0.2:41703 && scrcpy
Click to expand...
Click to collapse
And then I ran the Microsoft port query command (which is as slow as a lazy dog), but at least portqry.exe listed that port as "listening"...
c:\app\network\portqry\portqry -n 192.168.0.2 -e 41703
Querying target system called:
192.168.0.2
Attempting to resolve IP address to a name...
Failed to resolve IP address to name
querying...
TCP port 41703 (unknown service): LISTENING
Click to expand...
Click to collapse
Of course, I cheated as I already knew the port was 41703 by looking at the phone by longpressing on the new Android 12 "Developer options Wireless debugging tile" (which saves a bunch of steps digging into Android Settings and then Developer options).
But assuming I didn't know the port, but only knew the range, this would work (but it's horribly slow).
c:\app\network\portqry\portqry -n 192.168.0.2 -r 41700:41705
TCP port 41700 (unknown service): NOT LISTENING
TCP port 41701 (unknown service): NOT LISTENING
TCP port 41702 (unknown service): NOT LISTENING
TCP port 41703 (unknown service): LISTENING
TCP port 41704 (unknown service): NOT LISTENING
TCP port 41705 (unknown service): NOT LISTENING
Click to expand...
Click to collapse
Of course, I cheated by giving the slow portqry command a small range, as it would have taken forever to give it the range of 30000 to 40000 which is, so far, the range that I've seen being used.
Hindsight is so 20/20 in that once you've cheated such that you know the "static" IP & "random" port that Android set the new Android 12 Developer options Wireless debugging to, many basic network commands will quickly tell you that specific IP address is being used.
This will instantly report the "static" IP address of the adb-connected phone on my Windows 10 PC:
C:\> adb shell "ifconfig|grep -A 1 wlan0|tail -n 1|cut -f2 -d:|cut -f1 -d' '"
192.168.0.2
Click to expand...
Click to collapse
And, more to the point, the basic networking commands can tell you the random port - if - for example - if you had connected to it using adb yesterday or a week ago and that random port assignment had not changed in the interim...
This will tell you the "static" IP address and the "random" port:
C:\> netstat -ano -p tcp | findstr "192.168.0.2"
TCP 192.168.0.2:2392 192.168.0.2:41703 ESTABLISHED 1928
Note I left in the extraneous report of another port (2392) which was in use for reasons unknown to me...
Click to expand...
Click to collapse
What we need, of course, is a way to narrow down the range of ports that adb will use, which, to that end, I opened this thread about:
[adb,scrcpy,vysor] What ports does Android 12 randomly set when Wi-Fi connecting via Wireless debugging adb "pair" or "connect" commands?
GalaxyA325G said:
Of course, I already knew the port was 41703 by looking at the phone by longpressing on the new Android 12 "Developer options Wireless debugging tile" (which saves a bunch of steps digging into Android Settings and then Developer options).
Click to expand...
Click to collapse
TILE:
If I tap it, I can enable the option.
If I long press it, nothing happens and the tiles disappear immediately
> strange, isn't it ?
GalaxyA325G said:
I think there are two approaches to a solution.
1. Try to keep the port static, or,
2. Try to figure out the port (after the fact) in the batch file.
Click to expand...
Click to collapse
I think we have another option here:
3. Set IN ANDROID ADB the port we want.
That can be done using an Android.Bat activated by the wifi connection event
..... and HERE WE GO with the android terminal string for the standard port:
>> adb -d shell setprop service.adb.tcp.port 55555
Referring to:
Is it possible to adb connect android via wifi without configuring port on android?
I can connect via wifi by typing these codes in android terminal - setprop service.adb.tcp.port 5555 stop adbd start adbd and connect ip:port on PC adb .. it is connected .. Is there any possibi...
android.stackexchange.com
____________________________________________________________________
The following under bash:
$ export ANDROID_ADB_SERVER_PORT=12345
$ adb start-server
* daemon not running. starting it now on port 12345 *
* daemon started successfully *
$ adb devices
List of devices attached
TA2070M5O6 device
$ ANDROID_ADB_SERVER_PORT=6789 adb devices
* daemon not running. starting it now on port 6789 *
* daemon started successfully *
List of devices attached
Refering to:
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...
forum.xda-developers.com
________________________Start testing ______________________
Poor results >> I don't know Linux or Android enough
>> Please Step-In
___________________Waiting you ______________
I'm reading this:
Android Debug Bridge (adb) | Android Studio | Android Developers
Find out about the Android Debug Bridge, a versatile command-line tool that lets you communicate with a device.
developer.android.com
And we got a hit on the first 20 lines !!!
>>>>>> I take a break... see you in 7-9 hours
AlainCh2 said:
TILE:
If I tap it, I can enable the option.
If I long press it, nothing happens and the tiles disappear immediately
strange, isn't it ?
Click to expand...
Click to collapse
That is strange indeed.
The reason it matters is that this brand new Android 12 Developer options Wireless debugging tile saves a LOT of time daily digging into the Android settings (because it takes you exactly where you need to be to find out what the current random port assignment is).
I guess we need a third person to test it as when I tap the new tile, it toggles from on to off and from off to on... but when I longpress it, I end up deep inside the Developer options Wireless debugging Activity (whether or not the tile was blue or white at the time that I longpressed it).
I even just now tested it for you with the Wi-Fi radio turned off, and again with the Wi-Fi radio turned on but with no access point being connected.
In summary, even though the Developer option for Wireless debugging won't work without BOTH the Wi-Fi radio being turned on AND the Wi-Fi being connected to an access point (mine being set to NOT auto-reconnect, for privacy reasons), longpressing on the Developer options Wireless debugging tile brought me, every time, to the Developer options Wireless debugging screen.
I'm on a Samsung Galaxy A32-5G, Android 12, non rooted.​
Would someone else kindly test it for us to break the tie?
AlainCh2 said:
I think we have another option here:
3. Set IN ANDROID ADB the port we want.
Click to expand...
Click to collapse
I love the way you think!
Here are the possible solutions (thanks to you):
1. Keep the random port assignment static between adb connections
Or...
2. Determine the current random port assignment from the PC
Or...
3. Manually set the port assignment from the PC!
(Which is much like we used to do in the days of USB cable connections (where we would set it to 5555 and then disconnect once we set it to that static port).
I love how you think as you're trying to solve the same problem we all have, but you're using more tools to do it as you think outside the box by using all the methods available.
I will have to try this on the PC on the MSDOS command line (which is outside of Bash as I don't have Linux inside of the PC set up yet).
AlainCh2 said:
>> adb -d shell setprop service.adb.tcp.port 55555
Click to expand...
Click to collapse
I'll try to follow in your footsteps on the Windows 10 MSDOS command line (which requires a different style of environment variables)...
AlainCh2 said:
$ export ANDROID_ADB_SERVER_PORT=12345
Click to expand...
Click to collapse
This seems to be how to set Win10 user-specific environment variables...
C:\> setx [variable_name] "[variable_value]"​
And this is how to set Win10 system-wide environment variables:
Win+R > cmd {Ctrl+Shift+Enter} <-- admin window​setx [variable_name] "[variable_value]" /M​
Which means I can use this in the MSDOS admin cmd window:
Win+R > cmd {Ctrl+Shift+Enter}​setx ANDROID_ADB_SERVER_PORT "55555" /M​
AlainCh2 said:
$ adb start-server
* daemon not running. starting it now on port 12345 *
* daemon started successfully *
$ adb devices
List of devices attached
TA2070M5O6 device
Click to expand...
Click to collapse
I think I'm with you only up to this point... starting with...
a. Android has Wi-Fi turned on
c. Android has the Wi-Fi connected to an access point
d. Android has Developer options Wireless debugging = on
e. Which reports a static IP & random port of 192.168.0.2:41269
And then running these commands in your footsteps...
1. Win+R > cmd {Ctrl+Shift+Enter}
2. adb kill-server
3. setx ANDROID_ADB_SERVER_PORT "55555" /M
SUCCESS: Specified value was saved.
4. adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully
5. adb devices
List of devices attached
adb-SERIALNUMBER._adb-tls-connect._tcp. offline
6. set ANDROID_ADB_SERVER_PORT
Environment variable ANDROID_ADB_SERVER_PORT not defined
(funny... I thought I had already defined it, system wide... oh well... )
7. set ANDROID_ADB_SERVER_PORT=55555
8. set ANDROID_ADB_SERVER_PORT
ANDROID_ADB_SERVER_PORT=55555
Notice I'm with you up to this point so far...
AlainCh2 said:
$ ANDROID_ADB_SERVER_PORT=6789 adb devices
* daemon not running. starting it now on port 6789 *
* daemon started successfully *
List of devices attached
Click to expand...
Click to collapse
I don't (yet) understand what that command is doing so I can't even figure out how to reproduce it in the Windows 10 MSDOS batch command line.
AlainCh2 said:
View attachment 5676681
Click to expand...
Click to collapse
I remember seeing "setprop" stuff for adb when I had googled this, so we both need to look up what it does and what's the syntax.
AlainCh2 said:
>>>>>> I take a break... see you in 7-9 hours
Click to expand...
Click to collapse
I like how you think, which is that we "should" be able to set the port from WIndows that adb will connect to Android... but....
Remember all that "old" stuff predates Android 11 Developer options Wireless debugging (which is designed to use a random port assignment).
All that "old" stuff assumed a USB cable connection to the Android phone... which we aren't using....
... so what we have to do is figure out how to change that old stuff to get around the fact we can't talk to the phone unless we can figure out what port the phone is listening on...
This is the best I can do (but it's cheating)
a. Android has Wi-Fi turned on
c. Android has the Wi-Fi connected to an access point
d. Android has Developer options Wireless debugging = on
e. Which reports a static IP & random port of 192.168.0.2:41269
These commands ALWAYS work (but I had to cheat!)...
1. Win+R > cmd
2. adb kill-server
3. adb connect 192.168.0.2:41269
4. scrcpy --tcpip=192.168.0.2:41269
5. up pops the mirror of Android in the scrcpy GUI
While that works perfectly, the problem is that I have to KNOW the port before any of that works.
Hi,
as adb announces the service via MDNS, you can use the value of "persist.adb.wifi.guid" to connect.
output of avahi-discover under Ubuntu 20.04:
Code:
Service Type: _adb-tls-connect._tcp
Service Name: "value of persist.adb.wifi.guid"
Domain Name: local
Interface: eth0 IPv6
Address: Android.local/192.168.1.223:41465
TXT v = ADB_SECURE_SERVICE_VERSION
Or you can use "adb mdns services" to show all found devices in the network, see https://source.android.com/devices/automotive/virtualization/tools
Regards,
meiser
meiser said:
as adb announces the service via MDNS, you can use the value of "persist.adb.wifi.guid" to connect.
Click to expand...
Click to collapse
I don't know if I'm supposed to openly admit I have no clue what "mdns" even means, but I did use the "adb mdns services" command in post #3 above because I found it on the net when I had googled for how to tell which port adb is using.
C:\> netstat -ano -p tcp | findstr "192.168.0.2"
C:\> adb shell "ifconfig|grep -A 1 wlan0|tail -n 1|cut -f2 -d:|cut -f1 -d' '"
C:\> adb mdns services
C:\> nmap 192.168.0.2
Click to expand...
Click to collapse
The problem I had with using 'mdns' was that it sometimes gave me good port information and it sometimes did not (more often than not, it reported absolutely nothing useful) - yet - I haven't been able to figure out why - so I simply gave up on it a while ago.
Maybe I need to re-visit mdns because sometimes it gave what I wanted.
Googling, I find it's actually labeled mDNS, which now I only need to figure out what the "m" stands for since we're all familiar with DNS name-to-ipaddress lookups.
Googling some more, I find the "m" stands for "multicast" which still doesn't tell me a thing about what it is yet...
If you aren’t familiar, mDNS is a protocol defined by the Internet Engineering Task Force (IETF), the organization that oversees the technical standards that comprise the Internet. It stands for multicast domain name system, and it’s how hostnames are resolved on local networks without their own DNS server. The mDNS protocol is defined in full in the IETF’s RFC 6762 document, but the most relevant part is Section 5.1 – One-Shot Multicast DNS Queries, as it’s what Android’s DNS resolver implements.
Without getting too technical, mDNS basically makes it possible to connect to devices on a local network using human readable names, similar to how DNS makes it possible to connect to servers over the Internet using a human readable name.
Click to expand...
Click to collapse
What I'm guessing (at this point) is that Android will "announce" itself with a hostname of sorts using this "multicast DNS" protocol for the LAN, am I right?
Android, meanwhile, has offered support for mDNS service discovery since Android 4.1 Jelly Bean … but only for apps that implement the network service discovery (NSD) API. This means that Android users, for years now, haven’t been able to simply enter a hostname followed by .local into a web browser and have it be resolved to the IP address of a local device.
Click to expand...
Click to collapse
You mentioned "avahi" below... (which I also never heard of)...
meiser said:
output of avahi-discover under Ubuntu 20.04:
Code:
Service Type: _adb-tls-connect._tcp
Service Name: "value of persist.adb.wifi.guid"
Domain Name: local
Interface: eth0 IPv6
Address: Android.local/192.168.1.223:41465
TXT v = ADB_SECURE_SERVICE_VERSION
Click to expand...
Click to collapse
Now I see why you brought up "avahi" discover services...
Microsoft brought native support for mDNS to Windows with Windows 10 1703 in 2016, but prior to that, users could install Apple’s Bonjour Print Services tool to use the feature. Many Linux distros implement mDNS through the Avahi daemon. Apple, as the author of the protocol, of course has a native implementation in iOS and macOS.
Click to expand...
Click to collapse
The problem I've had with "adb mdns services" is sometimes it reports good information but other times it reports nothing.
meiser said:
Or you can use "adb mdns services" to show all found devices in the network, see https://source.android.com/devices/automotive/virtualization/tools
Click to expand...
Click to collapse
If we can figure out the circumstances as shown below where mDNS are in service, then the "adb mdns services" command might actually be useful to us to determine the Android 12 random port assignment.
1. Start with Android 12 & desktop PC connected to the LAN
2. Turn on Android Developer options Wireless debugging
3. Query Android for the wireless debugging port
The problem to resolve is...
a. When adb hasn't been run, mdns doesn't report anything
b. Even with adb connected, often mdns doesn't report anything
Yet...
c. Sometimes mdns DOES report the port address we seek
Why?
Screenshot: Notice we've been using "adb mdns services" for a while now but it rarely reports anything at all, let alone the random port assignment (but sometimes it does!).
GalaxyA325G said:
I love how you think as you're trying to solve the same problem we all have, but you're using more tools to do it as you think outside the box by using all the methods available.
Click to expand...
Click to collapse
That's what I did for a living in small companies like Olivetti, SIP/TelecomItalia, MCIWorldcom.
I'm a strange human being: I learned to program Assembler and PL1 in IBM, Gwbasic and COBOL on Mainframes, Honeywell OS, Digital PDP OS., and at last on Cisco routers
.... all by myself - and never worked programming ( but to better understand what was happening to my people)
______________________________________________
Sorry to say: you didn't got my lead correctly.
3: >android side
IF > we can run the equivalent of a ".BAT" file every time wifi connect
we can try setting the ADB port variable Android side,
making no assumptions on PC
But I don't know enough on that side,
nor do I know enough on Linux that's the Android base.
( I'm still curious - but brain is not agile anymore to learn fast to my liking)
AlainCh2 said:
That's what I did for a living in small companies like Olivetti, SIP/TelecomItalia, MCIWorldcom.
Click to expand...
Click to collapse
Yea, me too, where I worked in Silicon Valley startups for decades before retiring about 20 years ago...
AlainCh2 said:
I learned to program Assembler and PL1 in IBM, Gwbasic and COBOL on Mainframes, Honeywell OS, Digital PDP OS., and at last on Cisco routers
.... all by myself - and never worked programming ( but to better understand what was happening to my people)
Click to expand...
Click to collapse
Yup. I took Fortran (before there was a Fortran 77) on the IBM 1130 (as I recall) with tickertape just being phased out in favor of modern punch cards, and then moved on to PL/C (before there was a PL/1) and IBM Assembly Language and COBOL (which are just about the most divergent languages on the planet). Then the PDP 11, VAX/VMS, Masscomp, SunOS, Solaris, etc., until the PC grew up and I dropped all that 'nix stuff for Windows (and moved into management so I never did coding professionally - and I hate it - so I won't be doing it anytime soon).
But, like you, I do what I have to do in order to get the job done.
AlainCh2 said:
______________________________________________
Sorry to say: you didn't got my lead correctly.
Click to expand...
Click to collapse
Yeah. I'm Aspergers. I don't get anybody's jokes. Not just yours. But everyone's. Ask my wife and kids and grandkids.
On this thread I'm just trying to do what I am sure can be done, which is:
a. Run a PC command that queries the Android phone on the LAN
b. To spit out the random port Wireless debugging is set to
c. WITHOUT having initially connected USING that port in the first place!
It may not even be possible (since Android developers may have made it impossible for security reasons perhaps).
But until I find out that it's impossible - I'm assuming it's possible.
1. Sometimes we don't know which commands to use, and,
2. Sometimes we don't have the command syntax just yet... and,
3. Sometimes it is impossible (but that's rare, is it not?)
We just have to figure out which commands/syntax give us that missing port information.
GalaxyA325G said:
We just have to figure out which commands/syntax give us that missing port information.
Click to expand...
Click to collapse
Hehehe !! A parallel story, I'm younger but beaten bad by life: at 66, I'm pretty locked in a bed from 2017.
Had to stop working in 2015, and finally got anticipated retirement in 2019.
Asperger too.
( oh, and I mean we are not brother for sure - but magnetic communication exists)
3) >>I proposed a closed command program continuously running in Android.
It was not a Joke!
But maybe we can reach the same result from PC,
if we can access telnet console on android
AlainCh2 said:
I proposed a closed command program continuously running in Android.
It was not a Joke!
But maybe we can reach the same result from PC,
if we can access telnet console on android
Click to expand...
Click to collapse
I do very much like how you think... as you don't give up when encountering a technical hurdle - and - better yet - and nearer to my heart and soul - you - like I - assume naturally there will be a solution.
Maybe there is... hmmmmmmmm......
Along the line of your "closed command program" running on Android, I am testing this option I just found out of the open source local android debug bridge (ladb APK) which is designed to run adb on the Android phone in order to mimic the PC.
I'm hoping I can get the PC to communicate with that free open source ladb app which is said to have more privileges than does Termix on Android.
is there any app like LADB which can command phone through my phone with wireless debugging android 12 .I don't have any pc and LADB price is too high to afford.

[adb,scrcpy,vysor] What ports does Android 12 randomly set when Wi-Fi connecting via Wireless debugging adb "pair" or "connect" commands?

What ports does Android 12 randomly set when connecting wirelessly to adb via either the Wireless debugging "pair" or the "connect" adb PC commands?
Brief history:
While Android has forever been able to initially connect over TCP Port 5555 over USB first, and then the USB cable could have been disconnected to mirror Android over to the PC wirelessly on your LAN...
... As of Android 12, there are fantastic new "Developer options" for "Wireless debugging" which allow us to mirror Android over to any PC (Mac/Windows/Linux) without ever needing a USB cable ever again!
Brief background:
1. The wonderful screen mirroring tools (Vysor, Scrcpy, Sndcpy,etc.) connect using adb
2. We write scripts on the PC to mirror multiple devices onto the PC sans consoles
3. Each Android device has a random port assignment for adb "pair" & "connect" commands
C:\> adb connect 192.168.0.2:[RANDOM-PORT]​C:\> adb pair 192.168.0.2:[RANDOM-PORT] [RANDOM-PIN]​
We need a tool to TEST which random port Android 12 sets Developer options Wireless debugging to.
We have a variety of tools as described in this recent thread today:
(PSA) Using the new Android 12 TILE for 'Developer options' 'Wireless debugging' to establish adb connection over Wi-Fi without USB​
But those port-scanning tools take FOREVER to run on all possible ports.
Hence it behooves us to limit the port scan to just the ports Android 12 uses for Wireless debugging.
C:\> portqry -n 192.168.0.2 -r 30000:40000​C:\> netstat -ano -p tcp | findstr "92.168.0.2"​C:\> adb shell "ifconfig|grep -A 1 wlan0|tail -n 1|cut -f2 -d:|cut -f1 -d' '"​C:\> adb mdns services​C:\> nmap 92.168.0.2​etc.​
That is the reason I ask this very specific question:
What ports does Android 12 use for Developer options Wireless debugging?
I just came home and connected to scrcpy via adb over port 41703
C:\> adb connect 192.168.0.2:41703 && scrcpy
Click to expand...
Click to collapse
And then I ran the Microsoft port query command (which is slow as a lazy dog), but at least portqry.exe listed that port as "listening"...
c:\app\network\portqry\portqry -nr 192.168.0.2 -e 41703
Querying target system called:
192.168.0.2
Attempting to resolve IP address to a name...
Failed to resolve IP address to name
querying...
TCP port 41703 (unknown service): LISTENING
Click to expand...
Click to collapse
Of course, I already knew the port was 41703 by looking at the phone by longpressing on the new Android 12 "Developer options Wireless debugging tile" (which saves a bunch of steps digging into Android Settings and then Developer options).
But assuming I didn't know the port, but only knew the range, this would work (but it's horribly slow).
c:\app\network\portqry\portqry -n 192.168.0.2 -r 41700:41705
TCP port 41700 (unknown service): NOT LISTENING
TCP port 41701 (unknown service): NOT LISTENING
TCP port 41702 (unknown service): NOT LISTENING
TCP port 41703 (unknown service): LISTENING
TCP port 41704 (unknown service): NOT LISTENING
TCP port 41705 (unknown service): NOT LISTENING
Click to expand...
Click to collapse
Of course, once you know the IP address & port Android randomly set the new Android 12 Developer options Wireless debugging to, many basic network commands will tell you that port is being used by adb on that IP address, for example...
C:\> adb shell "ifconfig|grep -A 1 wlan0|tail -n 1|cut -f2 -d:|cut -f1 -d' '"
192.168.0.2
Click to expand...
Click to collapse
Where once you know the IP address, you can query the port.
C:\> netstat -ano -p tcp | findstr "192.168.0.2"
TCP 192.168.0.2:2392 192.168.0.2:41703 ESTABLISHED 1928
Click to expand...
Click to collapse
But... I knew the port ahead of time by looking on the phone to see what the random port the new Android 12 Developer options Wireless debugging had set the phone to.
What we need, of course, is a way to narrow down the range of ports that adb will use, which, to that end, I opened this thread.
BTW a search shows EVERYONE has the same adb wi-fi needs!
ADB Wifi, how to specify port and have it fix
[Q] Is it possible to adb connect via wifi without configuring port on android?
Connect Android phone over Wi-Fi using ADB
adb over wi-fi
[TUT] ADB over WI-FI
How to add WiFi network over ADB without root?
[GUIDE] How to connect adb over wifi
ADB Via WiFi
Adb over wifi
ADB-Over-WiFi
[APP] ADB WiFi
[APP] [4.1+] [OPEN SOURCE] WiFi ADB (Kotlin)
ADB over WiFi missing from developer option
ADB Via WiFi doesn't work.
adb over wifi without root?
[TUTORIAL] ADB over WiFi / TCP
[Q] adb over wifi?? without root
[APP] ADB WiFi
Adb over wifi
how can i enable adb over wifi
ADB over wifi
[Q] ADB only over wIFI no USB
Adb over wifi
[Q] ADB over wifi, no USB to accept RSA key
[Q] Is it possible to adb connect via wifi without configuring port on android?
[PYTHON SCRIPT][WINDOWS]Start scrcpy over Wi-Fi
[APP][8.0.0+][ROOT] Start ADB Over Wi-Fi [Root]
UPDATE:
It's IMPORTANT to be able to know what the random port is from the PC (without needing to touch the Android phone at all).
Making use of a 2012 thread today...
How to make adb listen to tcpip 5555 after reboot​
@AlainCh2 came up with a third option:
1. The first option is to try to keep the random port static
2. The second option is to figure out what it is from the PC alone
However... In that ancient thread, a third option was described...
3. Try to SET the port over Wi-Fi (without USB!) from the PC
Which @AlainCh2 experimented with over here today in post #10.
This is the best I can do (but it's cheating)
a. Non-rooted Android 12 has Wi-Fi turned on
c. Android has the Wi-Fi connected to an access point
d. Android has Developer options Wireless debugging = on
e. Which reports a static IP & random port of 192.168.0.2:41269
Once I already know the random port assignment, these commands ALWAYS work (but I had to cheat!)...
1. Win+R > cmd
2. adb kill-server
3. adb connect 192.168.0.2:41269
4. scrcpy --tcpip=192.168.0.2:41269
5. up pops the mirror of Android in the scrcpy GUI
View attachment 5677027
While that works perfectly, the problem is that I have to KNOW the port before any of that works.
My setup for scrcpy, 1 device:
1. Connect phone and PC to the same network.
2. Connect the phone to the PC via cable, execute command "scrcpy -d --tcpip" then scrcpy will setup the rest
scrcpy will set the port automatically to 5555 and try to establish a connection. No need to look for ports somewhere.
You may then disconnect the cable from PC. Just make sure you have a static IP for convenience. You don't need to enable wireless debugging for the port or anything. You just need to execute the steps above once every reboot. You may connect multiple devices. When executing the steps above, just make sure only one device is connected via cable at a time. You may then execute "scrcpy -s (ip)" or "scrcpy --tcpip=(ip)" to connect to one of the devices. If only one is connected wirelessly, "scrcpy -e" will do.
wildcatacu said:
My setup for scrcpy, 1 device:
1. Connect phone and PC to the same network.
2. Connect the phone to the PC via cable, execute command "scrcpy -d --tcpip" then scrcpy will setup the rest
scrcpy will set the port automatically to 5555 and try to establish a connection. No need to look for ports somewhere.
You may then disconnect the cable from PC. Just make sure you have a static IP for convenience. You don't need to enable wireless debugging for the port or anything. You just need to execute the steps above once every reboot. You may connect multiple devices. When executing the steps above, just make sure only one device is connected via cable at a time. You may then execute "scrcpy -s (ip)" or "scrcpy --tcpip=(ip)" to connect to one of the devices. If only one is connected wirelessly, "scrcpy -e" will do.
Click to expand...
Click to collapse
Nice, I can say it works
But I have to run scrcpy -d --tcpip only if I reboot tablet (in my case) or also if I restart pc?
If only the PC is restarted, there's no need to reconnect the android device via USB. To reconnect, you just need to run this command replacing the IP address (preferably set to static for convenience): scrcpy --tcpip=(Local IP Address). If you set your device's static IP to 192.168.1.24 for example, run the command: scrcpy --tcpip=192.168.1.24
As long as the Android device doesn't shut down or restart, you may reconnect to it anytime. PC can be shut down or restarted. The initial wired setup is only required on the Android device's first boot.

Categories

Resources