Comments (5)
from ENV? for example env:ANDROID_ADB_SERVER_PORT
from adbutils.
Hi, I'm not looking for the port of the adb server, but the adb port of the client device. Android 10 and below I believe always used 5555, but now it is random.
My adb server is Windows 10 but don't think that matters.
I believe the random port can be between 30000 and 60000, but not 100% sure.
Maybe a multi threaded port scan function could be added?
from adbutils.
I solved this by making a multi threaded port scanner and attempting to connect. This may not work right out of the box (I tried to copy the relevant parts out of my script)
import socket
from adbutils import adb
def myfunction(clientIP):
global scannerIP
scannerIP = clientIP
adbRanges = [ [5555, 5585], [30000 , 50000] ] #https://www.reddit.com/r/tasker/comments/jbzeg5/adb_wifi_and_android_11_wireless_debugging/
for adbRange in adbRanges:
adbThreadedScan(adbRange)
adbAddress = adbConnect(clientIP, adbPortsFound)
if adbAddress != None:
device = adb.device(serial=adbAddress)
break
def adbConnect(clientIP, adbPortsFound):
for adbPort in adbPortsFound:
adbAddress = clientIP + ':' + str(adbPort)
adbConnectOutput = adb.connect(adbAddress)
message = adbConnectOutput.split(clientIP + ':' + str(adbPort), 1)[0].strip()
if message == 'connected to' or message == 'already connected to':
logging.info('adb connected on port: %s' % (adbPort))
return adbAddress
def adbThreadedScan(adbRange):
from threading import Thread
from queue import Queue
# number of threads, imported from dictionary of preferences
rangeThreads = adbRange[-1] - adbRange[0]
prefThreads = Prefs['int_PortScanThreads']
if rangeThreads < prefThreads:
N_THREADS = rangeThreads
else:
N_THREADS = prefThreads
# thread queue
global q
q = Queue()
global adbPortsFound
adbPortsFound = []
for t in range(N_THREADS):
try:
#for each thread, start it
t = Thread(target=port_scan_thread)
#when we set daemon to true, that thread will end when the main thread ends
t.daemon = True
#start the daemon thread
t.start()
except RuntimeError as e:
break
for port in range(adbRange[0], adbRange[-1]):
if (port % 2) != 0: #if port is an odd number
#for each port, put that port into the queue
#to start scanning
q.put(port)
q.join() #wait for all ports to finish being scanned
def port_scan(host, port): #determine whether `host` has the `port` open
try:
# creates a new socket
s = socket.socket()
# tries to connect to host using that port
s.connect((host, port))
# make timeout if you want it a little faster ( less accuracy )
# s.settimeout(0.2)
except:
# cannot connect, port is closed
pass
else:
# the connection was established, port is open!
adbPortsFound.append(port)
finally:
s.close()
def port_scan_thread():
while True:
# get the port number from the queue
port = q.get()
# scan that port number
port_scan(scannerIP, port)
# tells the queue that the scanning for that port
# is done
q.task_done()
I will keep this open, but if the dev would like to close it that's fine. It would be nice to see the functionality added to this library.
from adbutils.
@ReenigneArcher https://github.com/openatx/adbutils/invitations
from adbutils.
I'm still struggling to find a good solution to this, as port scanning is slow. Honestly I do not understand why Android decided to go with the random ports and complicated pairing process.
from adbutils.
Related Issues (20)
- Issue with `device.sync.push` Resulting in `AdbError: FAIL` HOT 3
- Feature Request: Add `restart_adb_server()` Function to Simplify ADB Server Restart HOT 10
- ADB 录制屏幕失败 HOT 3
- 可以在_proto.py里面增加AppInfo类型的返回码?
- ModuleNotFoundError: No module named 'apkutils2.axml.axmlparser' HOT 2
- How to connect a vpn HOT 1
- AttributeError: module 're' has no attribute 'Pattern' HOT 5
- Does this library support connecting devices via usb? HOT 1
- Address already in use HOT 3
- FASTBOOT HOT 1
- no re.Pattern in re module HOT 1
- Non-Frozen dataclass lead to UnHashAble Error
- 如何实现使用 adbutils 查看特定的设备状态
- Python3.10版本collections包报错 HOT 3
- 1.2.11 device.install 不支持配置flags参数了 HOT 1
- adbutils 1.2.11 has an incorrect `python_requires` spec HOT 1
- adb.shell如何执行可执行文件或者.sh脚本?
- 什么时候需要实例化多个adbclient? HOT 1
- vscode插件都不支持py3.6了。啥时候考虑升级一下? HOT 2
- MultiScreen Support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adbutils.