通过本地网络使用Google的Python-ADB



正如标题所说,有没有一种方法可以使用谷歌的Python ADB库连接到网络上启用ADB over TCP的设备?

我在adb_commands.py文件中看到了一些与TCP连接有关的内容,下面是评论:

If serial specifies a TCP address:port,
then a TCP connection is used instead of a USB connection.

然而,没有这样做的例子。

我有设备的IP地址和端口,以及正确的ADB密钥,我想知道是否有人可以提供一个示例代码片段。

感谢:(

附言:我使用的是python3.7,这是uname -a:的输出

Linux Kali 4.18.0-kali2-amd64 #1 SMP Debian 4.18.10-2kali1 (2018-10-09) x86_64 GNU/Linux

是的,只需将ip:port传递给serial位置参数:

import os.path as op
from adb import adb_commands
from adb import sign_m2crypto
# KitKat+ devices require authentication
signer = sign_m2crypto.M2CryptoSigner(
op.expanduser('~/.android/adbkey'))
# Connect to the device
device = adb_commands.AdbCommands()
device.ConnectDevice(port_path=None, serial="192.168.0.140:5555",
rsa_keys=[signer])
# Now we can use Shell, Pull, Push, etc!
# for i in range(10):
#     print device.Shell('echo %d' % i)
print device.Shell('uname -a').rstrip()
print "%s, %s" % (device.Shell('getprop ro.product.brand').rstrip(),
device.Shell('getprop ro.product.model').rstrip())
print device.Shell('getprop ro.build.version.release').rstrip()
print device.List('/system')

我的设备上的输出:

Linux localhost 4.4.78-perf-g27c78a6 #1 SMP PREEMPT Thu Sep 6 03:28:28 CST 2018 aarch64
Xiaomi, MI 6
8.0.0
[DeviceFile(filename=bytearray(b'.'), mode=16877,
...

用Python 2.7.15测试;该库尚未完全准备好py3。请注意,您仍然需要先通过adb tcpip 5555或其他端口使设备在tcpip模式下侦听

最新更新