Files
to_session/process/设置ip.py
Administrator a0720d80dc fefdwef
2025-11-12 12:54:37 +08:00

72 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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')},修改代理失败!!!")