仲天
首页
(current)
分类
Go
Python
自动化脚本
xTS(谷歌认证测试)
Selenium
软件测试
Redis
Mysql
Docker
MongoDB
Jquery
Nginx
Bootstrap
Linux
正则表达式
bat
cmd批处理
截图
作者分享
JSON
SEO
在线工具
搜索
Python手机自动化脚本
2022-07-20 14:19:31
344
本文章为原创文章,转载请附上原文地址,谢谢。
```python # !/usr/bin/python # _*_ coding:utf-8 _*_ import os import re import time from colorama import init init(autoreset=True) # 获取电脑屏幕的宽度 width = os.get_terminal_size().columns # 自动wifi连接 def auto_wifi_connect(): print("\033[0;32;40m自动连接wifi\033[0m".center(width, '*')) os.popen("adb push WifiConfigStore.xml /data/misc/wifi/") os.popen("adb reboot") # 计时 index = 1 while True: time.sleep(1) if len(get_devices_sn()) > 0: break else: # 最大等待时间1分钟 if index == 90: print("\033[0;31;40m手机重启超时\033[0m".center(width, '*')) return index += 1 continue os.popen("adb root") # 打开飞行模式 def open_flight_mode(): print("\033[0;32;40m打开飞行模式\033[0m".center(width, '*')) os.popen("adb shell settings put global airplane_mode_on 1") os.popen("adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true") # 设置熄屏 def rest_screen(): # 等待30分钟 time.sleep(1800) print("\033[0;32;40m熄灭屏幕-等待30秒\033[0m".center(width, '*')) os.popen("adb shell input keyevent 26") # 执行命令 def execute_command(): print("\033[0;32;40m执行命令(location off and duraspeed off)\033[0m".center(width, '*')) os.popen("location off") os.popen("duraspeed off") # 主函数 def main(): print('''* 1.手机需要先连上wifi,然后输入"adb pull /data/misc/wifi/WifiConfigStore.xml"拉取出"WifiConfigStore.xml"文件。''') print('''* 2.将"WifiConfigStore.xml"文件放在zzt_auto.py(脚本)或zzt_auto.exe同级目录,未push文件的手机必须做一次。''') input_data = input('''* 请告诉我,需要push "WifiConfigStore.xml"文件到手机吗?这个过程会重启手机(Y/Enter)''') # 检测手机是否连接和获取sn号 sn_list = get_devices_sn() if len(sn_list) < 1: print("\033[0;31;40m没有手机连接\033[0m".center(width, '*')) return print("\033[0;32;40mSN:{}\033[0m".format(sn_list[0]).center(width, '*')) # adb root os.popen("adb root") # 自动连接wifi if input_data == "Y" or input_data == "y": auto_wifi_connect() os.popen("adb shell svc wifi enable") # 打开飞行模式 open_flight_mode() # 熄灭屏幕 rest_screen() # 执行命令 execute_command() # 结束 print("\033[0;32;40m测试完成\033[0m".format(sn_list[0]).center(width, '*')) # 获取SN号 def get_devices_sn(): sn_list = [] device_info = os.popen('adb devices').read() for line in device_info.splitlines(): if line == 'List of devices attached': continue else: com = re.compile('(.*?)\tde.*?') sn = re.findall(com, line) for i in sn: sn_list.append(i) return sn_list if __name__ == '__main__': try: main() except: input("输入任意字符结束") ```
版权声明:本文为仲天原创文章,转载请附上原文出处链接和本声明。
本文链接:
文章分类
Go
Python
自动化脚本
xTS(谷歌认证测试)
Selenium
软件测试
Redis
Mysql
Docker
MongoDB
Jquery
Nginx
Bootstrap
Linux
正则表达式
bat
cmd批处理
截图
作者分享
JSON
SEO
推荐文章
搜索引擎提交入口大全,站长平台地址大全
154
推荐一个在线json工具,可格式化、可压缩、可检查。
150
Python手机自动化脚本
344
golang读取json文件,第三方库
419
各系统截图快捷键汇总大全,包括windows、linux、mac、安卓、ios。
438
优选网站
在线JSON工具
在线音频提取
Linux在线大全
PDF转WORD
TCP/IP端口大全