本帖最后由 打字的小强 于 2018-11-28 10:05 编辑
一直想弄个真机群控,vnc监控,要用脚本语言控制手机好像只能用shell类似的adb脚本了。然后弄个vnc监控什么的。已经开始弄adb群控脚本了,自己只懂点python,并不会底层的什么东西,后期肯定要改底层的东西,用到c之类的语言了。搜集各种资料试了一下,已经实现了两个功能,挺有意思的。初步分享下adb群控原理
[Python] 纯文本查看 复制代码
# !/usr/bin/python
# -*- coding:utf-8 -*-
import os
runapp_name = "com.tencent.mobileqq/.activity.SplashActivity"
def getDevicesAll():
#获取所有的设备列表
devices = []
try:
for dName_ in os.popen("adb devices"):
if "\t" in dName_:
if dName_.find("emulator") < 0:
devices.append(dName_.split("\t")[0])
devices.sort(cmp=None, key=None, reverse=False)
except:
pass
print("设备名称: %s 总数量:%s台" % (devices, len(devices)))
return devices
def find_top_app(devices):
# 循环输入顶层应用
for dName in devices:
try:
out = os.popen('adb shell "dumpsys activity | grep "mFocusedActivity""').read()
print(dName+"的当前顶层应用是:"+out)
except:
print(dName + "关闭失败")
def runtest(devices):
# 打开应用
for dName in devices:
try:
os.popen("adb -s " + dName +" shell am start -n "+runapp_name)
print("启动成功")
except:
print(dName+"打开失败")
if __name__=="__main__":
while True:
try:
devices = getDevicesAll()
except:
print("获取设备出错")
res = input("输入1查看当前的顶层app;2启动qq:")
if int(res)==1:
try:
find_top_app(devices)
except:
print("启动错误")
elif int(res)==2:
try:
runtest(devices)
except:
print("启动错误")
|