Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

* gb notes that fdisk thinks his cdrom can store one terabyte -- Seen on #Linux


computers / alt.internet.wireless / PSA: How to get the random Android wireless debugging port from Windows?

SubjectAuthor
o PSA: How to get the random Android wireless debugging port from Windows?Andy Burnelli

1
PSA: How to get the random Android wireless debugging port from Windows?

<tb9jfe$13ml$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=327&group=alt.internet.wireless#327

  copy link   Newsgroups: comp.mobile.android alt.comp.os.windows-11 alt.internet.wireless
Path: i2pn2.org!i2pn.org!aioe.org!3PLzD/rb74ta/CXxNcmbeA.user.46.165.242.75.POSTED!not-for-mail
From: spam@nospam.com (Andy Burnelli)
Newsgroups: comp.mobile.android,alt.comp.os.windows-11,alt.internet.wireless
Subject: PSA: How to get the random Android wireless debugging port from Windows?
Date: Wed, 20 Jul 2022 20:02:34 +0100
Organization: Aioe.org NNTP Server
Message-ID: <tb9jfe$13ml$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="36565"; posting-host="3PLzD/rb74ta/CXxNcmbeA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1
Content-Language: en-GB
X-Notice: Filtered by postfilter v. 0.9.2
 by: Andy Burnelli - Wed, 20 Jul 2022 19:02 UTC

PSA: How to get the random Android wireless debugging port from Windows?
Woo hoo!

I found a solution to the problem set Android Wireless debugging posed:
*Is there a way to put a command window in the background like Linux does*
(so that you can kill the Android mirroring console named scrcpy?)
<https://groups.google.com/g/alt.msdos.batch/c/DmexCLwn_tM>

*IMPORTANT UPDATE* to work around the total absence of 'Ctrl-Z,bg' in
Windows, which badly affects Android:Windows adb Wi-Fi efficiency!
<https://i.postimg.cc/zfLp8b2v/adb22.jpg> New 'Ctrl+Z,bg' workaround

It took me days (elapsed time) to figure out this latest workaround
to the complete and utter total lack of 'Ctrl+Z,bg' in Windows.

Yet, the final solution turns out to be incredibly simple.
If you know a few of the tricks, that is.

This lack of 'Ctrl+Z,bg' is a horrible deficiency of Windows indeed.
Luckily, with your help, we created a USB 'Ctrl+Z,bg' workaround.

And, after testing for days, *we have a Wi-Fi 'Ctrl+Z,bg' workaround.*

This new 'Ctrl+Z,bg' workaround can now be added to the existing
'Ctrl+Z,bg' workaround batch script kindly authored by Herbert.

It need only be a variable, e.g., %GET-RANDOM-PORT-ASSIGNMENT%

As you may recall, the 'Ctrl+Z,bg' workaround script Herbert kindly
proposed was to solve the lack of 'Ctrl+Z,bg' in Windows given
conditions of an initial USB connection.

That initial USB connection only needed a _static_ port address.

So the previous 'Ctrl+Z,bg' workaround script worked fine as that
previous 'Ctrl+Z,bg' workaround script didn't need to query Android
for the port address.

The problem that arose in Android 11+ is the addition of Wireless
debugging which necessitated the 'Ctrl-Z,bg' workaround batch script
now knowing, a priori, what that randomly assigned wireless debugging
IP address is.

But how?
Specifically, how do you query Android WITHOUT first establishing
a connection to it (where that connection _requires_ the random port!).

Seemingly that's impossible, right?
Ah, but it's not impossible.

It took me a few days (elapsed time) to figure out how to query Android
from Windows to _obtain_, a priori, that randomly assigned IP address!

Luckily I found two Windows commands which will obtain that random port:
C:\> netstat -ano -p tcp | findstr "192.168.1.10"
C:\> adb mdns services

Below is a log file reproducing the steps in only a minute or two.
<https://i.postimg.cc/zfLp8b2v/adb22.jpg> New 'Ctrl+Z,bg' workaround
----------------------
Log file for this image: <https://i.postimg.cc/zfLp8b2v/adb22.jpg>
C:\app\editor\android\scrcpy>netstat -ano -p tcp | findstr "192.168.1.10"

C:\app\editor\android\scrcpy>adb shell "ifconfig|grep -A 1 wlan0|tail -n
1|cut -f2 -d:|cut -f1 -d' '"
* daemon not running; starting now at tcp:5037
* daemon started successfully
adb.exe: no devices/emulators found

C:\app\editor\android\scrcpy>adb devices
List of devices attached

C:\app\editor\android\scrcpy>adb mdns services
List of discovered mdns services

C:\app\editor\android\scrcpy>On Android, turn wi-fi on & connect to the LAN
(wait a minute or two)

C:\app\editor\android\scrcpy>netstat -ano -p tcp | findstr "192.168.1.10"

C:\app\editor\android\scrcpy>adb shell "ifconfig|grep -A 1 wlan0|tail -n
1|cut -f2 -d:|cut -f1 -d' '"
adb.exe: no devices/emulators found

C:\app\editor\android\scrcpy>adb devices
List of devices attached

C:\app\editor\android\scrcpy>adb mdns services
List of discovered mdns services

C:\app\editor\android\scrcpy>Now turn on Developer options, Wireless
debugging & accept the "Allow" (wait 2 min)

C:\app\editor\android\scrcpy>Note that the phone knows the address & port
of 192.168.1.10:36999 (not the PC)

C:\app\editor\android\scrcpy>When the phone beeps with "Wireless debugging
connected", you're ready

C:\app\editor\android\scrcpy>netstat -ano -p tcp | findstr "192.168.1.10"
TCP 192.168.1.27:49765 192.168.1.10:36999 ESTABLISHED 3208

C:\app\editor\android\scrcpy>Bingo! The PC now knows the Wireless debugging
IP address & random assigned port!

C:\app\editor\android\scrcpy>adb shell "ifconfig|grep -A 1 wlan0|tail -n
1|cut -f2 -d:|cut -f1 -d' '"
192.168.1.10

C:\app\editor\android\scrcpy>Windows adb knows only the IP address (but not
the randomly assigned wireless port) :(

C:\app\editor\android\scrcpy>adb devices
List of devices attached
adb-ABCEFGHIJKL-123456._adb-tls-connect._tcp. device

C:\app\editor\android\scrcpy>adb mdns services
List of discovered mdns services
adb-ABCEFGHIJKL-123456._adb-tls-connect._tcp. 192.168.1.10:36999

C:\app\editor\android\scrcpy>Ah. Nice. So Windows adb DOES know the IP
address & randomly assigned wireless debug port

C:\app\editor\android\scrcpy>scrcpy.exe
scrcpy 1.24 <https://github.com/Genymobile/scrcpy>
C:\app\editor\android\scrcpy\scrcpy-server: 1 file pushed, 0 skipped. 0.8
MB/s (41159 bytes in 0.051s)
[server] INFO: Device: samsung SM-A326U (Android 12)
INFO: Renderer: direct3d
INFO: Initial texture: 720x1600

At this point you would die for a "control-Z bg" command sequence.
If that 'Ctrl+Z,bg' existed on Windows, this thread wouldn't be needed.
But alas, Windows completely lacks such a 'Ctrl+Z,bg' luxury.
Hence the need for a 'Ctrl+Z,bg' workaround batch script.

If 'Ctrl+Z,bg' existed on Windows, we would never have this problem
of querying Android from Windows to obtain the Wireless-debugging
port random assignment (because scrcpy console does NOT need it!).

But if we want to eliminate the scrcpy console, then we need to
find a workaround to the fact that Windows completely lacks a
basic 'Ctrl+Z,bg' functionality. <=== this is the problem!

Since 'Ctrl+Z,bg' does NOT exist on the PC, we need to tell
the 'Ctrl+Z,bg' workaround batch script what that randomly assigned
port is set to on Android WITHOUT looking at Android.

The 'Ctrl+Z,bg' workaround script must figure it out on its own!
Hence you must figure out the random port assignment from the PC.

Notice scrcpy with the console does NOT need to know this port.
It figures it out on its own.

So it's only the 'Ctrl+Z,bg' workaround script that NEEDS this port.
All we need now is to ADD that new 'Ctrl+Z,bg' variable to the script!

In summary, the old USB 'Ctrl+Z,bg' workaround, which expects a static
port,
only needs to have added a new 'Ctrl+Z,bg' variable,
e.g., %GET-RANDOM-PORT-ASSIGNMENT%

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor