72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
|
|
import json
|
|||
|
|
|
|||
|
|
import subprocess
|
|||
|
|
|
|||
|
|
from loguru import logger
|
|||
|
|
import uiautomator2 as u2
|
|||
|
|
|
|||
|
|
result1 = r"C:\Program Files\Netease\MuMu\nx_main"
|
|||
|
|
|
|||
|
|
|
|||
|
|
def mumu_get_list_all():
|
|||
|
|
# 定义命令
|
|||
|
|
command = [result1 + r"\MuMuManager.exe", "info", "-v", "all"]
|
|||
|
|
|
|||
|
|
# 运行命令并捕获输出,使用 utf-8 编码
|
|||
|
|
result = subprocess.run(command, capture_output=True, text=True, encoding='utf-8')
|
|||
|
|
|
|||
|
|
# 检查命令是否成功执行
|
|||
|
|
if result.returncode != 0:
|
|||
|
|
return None
|
|||
|
|
|
|||
|
|
# 解析 JSON 输出
|
|||
|
|
try:
|
|||
|
|
info = json.loads(result.stdout)
|
|||
|
|
|
|||
|
|
infos = []
|
|||
|
|
for i in info:
|
|||
|
|
infos.append(info[i])
|
|||
|
|
|
|||
|
|
return infos # 返回一个包含嵌套字典的列表
|
|||
|
|
except json.JSONDecodeError as e:
|
|||
|
|
return None
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == '__main__':
|
|||
|
|
|
|||
|
|
with open('代理配置.txt', 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
lines = content.split('\n')
|
|||
|
|
pro = {}
|
|||
|
|
for line in lines:
|
|||
|
|
pro[line.split("|")[-2]] = line.split("|")
|
|||
|
|
|
|||
|
|
mumu_lists = mumu_get_list_all()
|
|||
|
|
if mumu_lists:
|
|||
|
|
for mumu_info in mumu_lists:
|
|||
|
|
if mumu_info.get("is_android_started"):
|
|||
|
|
try:
|
|||
|
|
d = u2.connect(f"127.0.0.1:{mumu_info.get("adb_port")}")
|
|||
|
|
|
|||
|
|
# 定义命令
|
|||
|
|
command = [
|
|||
|
|
fr'{result1}\adb.exe',
|
|||
|
|
'-s',
|
|||
|
|
f'127.0.0.1:{mumu_info.get("adb_port")}',
|
|||
|
|
'shell',
|
|||
|
|
'settings',
|
|||
|
|
'put',
|
|||
|
|
'global',
|
|||
|
|
'http_proxy',
|
|||
|
|
# f'{pro.get(mumu_info.get("index"))[0]}:{pro.get(mumu_info.get("index"))[1]}'
|
|||
|
|
f':0'
|
|||
|
|
]
|
|||
|
|
# 运行命令并捕获输出,使用 utf-8 编码
|
|||
|
|
result = subprocess.run(command, capture_output=True, text=True, encoding='utf-8')
|
|||
|
|
|
|||
|
|
logger.info(f"模拟器id:{mumu_info.get('index')},修改代理成功!!!")
|
|||
|
|
except Exception as e:
|
|||
|
|
print(e)
|
|||
|
|
logger.error(f"模拟器id:{mumu_info.get('index')},修改代理失败!!!")
|