通过本地网络使用 Google 的 Python-ADB
Using Google's Python-ADB over a local network
正如标题所说,不言自明,有没有办法使用 Google 的 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 密钥,我想知道是否有人可以提供示例代码片段。
多谢 :)
P.S。我正在使用 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
模式下侦听。
正如标题所说,不言自明,有没有办法使用 Google 的 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 密钥,我想知道是否有人可以提供示例代码片段。
多谢 :)
P.S。我正在使用 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
模式下侦听。