# !/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("输入任意字符结束")
手机自动化脚本
最新推荐文章于 2024-04-18 20:40:06 发布