1
1
This commit is contained in:
18
modules/Send.py
Normal file
18
modules/Send.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import requests
|
||||
|
||||
# 定义服务端的 URL
|
||||
|
||||
def data_to_server(url,data):
|
||||
try:
|
||||
# 发送 POST 请求并将数据包含在请求体中
|
||||
response = requests.post(url, json=data)
|
||||
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 响应成功,可以访问响应内容
|
||||
result = response.json() # 如果服务端返回 JSON 数据
|
||||
print(result)
|
||||
else:
|
||||
print(f"请求失败,状态码:{response.status_code}")
|
||||
except requests.RequestException as e:
|
||||
print(f"请求出现错误:{e}")
|
||||
0
modules/__init__.py
Normal file
0
modules/__init__.py
Normal file
BIN
modules/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
modules/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/command.cpython-39.pyc
Normal file
BIN
modules/__pycache__/command.cpython-39.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/device.cpython-39.pyc
Normal file
BIN
modules/__pycache__/device.cpython-39.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/fileRW.cpython-39.pyc
Normal file
BIN
modules/__pycache__/fileRW.cpython-39.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/read_config.cpython-39.pyc
Normal file
BIN
modules/__pycache__/read_config.cpython-39.pyc
Normal file
Binary file not shown.
103
modules/command.py
Normal file
103
modules/command.py
Normal file
@@ -0,0 +1,103 @@
|
||||
import subprocess
|
||||
import logging
|
||||
import time
|
||||
def run_adb_command(command_list):
|
||||
process = subprocess.Popen(command_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = process.communicate()
|
||||
output = stdout.decode().strip()
|
||||
status_code = process.returncode
|
||||
error = stderr.decode().strip()
|
||||
return output, status_code, error
|
||||
|
||||
def get_now_time(device):
|
||||
# adb shell date +%s
|
||||
output, status_code, error = run_adb_command(['adb', '-s', device, 'shell', 'date', '+%s'])
|
||||
if status_code == 0:
|
||||
print(f"get_now_time output: {output}")
|
||||
logging.info(f"get now time output: {output}")
|
||||
now_timestamp = int(output)
|
||||
return now_timestamp
|
||||
else:
|
||||
print(error)
|
||||
logging.error(f"get now time error: {error}")
|
||||
return None
|
||||
|
||||
def get_record(device):
|
||||
logging.debug(device)
|
||||
# adb -s <设备序列号> pull <远程路径> <本地路径>
|
||||
output, status_code, error = run_adb_command(['adb', '-s', device, 'pull', '/sdcard/rizhi/record.txt','./cache'])
|
||||
if status_code == 0:
|
||||
print(output)
|
||||
logging.info(f"get record output: {output}")
|
||||
return True
|
||||
else:
|
||||
print(error)
|
||||
logging.error(f"do get_record failed,error:{error}")
|
||||
return False
|
||||
|
||||
|
||||
def stopAutojs(device):
|
||||
print(f"{device},强行停止 Auto.js")
|
||||
output, status_code, error = run_adb_command(['adb', '-s', device, 'shell', 'am', 'force-stop', 'org.autojs.autojs'])
|
||||
if status_code == 0:
|
||||
logging.info(f"stop Autojs status_code:{status_code}")
|
||||
return True
|
||||
else:
|
||||
print(error)
|
||||
logging.error(f"stop Auto.js error: {error}")
|
||||
return False
|
||||
|
||||
def clearCache(device):
|
||||
print(f"{device},清理缓存")
|
||||
output, status_code, error = run_adb_command(['adb', '-s', device, 'shell', 'pm', 'clear', 'sperixlabs.proxyme'])
|
||||
if status_code == 0:
|
||||
logging.info(f"clear cache status_code: {status_code}")
|
||||
return True
|
||||
else:
|
||||
print(error)
|
||||
logging.error(f"clear cache error: {error}")
|
||||
return False
|
||||
|
||||
|
||||
def openProxyMe(device):
|
||||
print(f"{device},打开 ProxyMe")
|
||||
output, status_code, error = run_adb_command(['adb', '-s', device, 'shell', 'am', 'start', '-n', 'sperixlabs.proxyme/tun.proxy.MainActivity'])
|
||||
if status_code == 0:
|
||||
logging.info(f"open ProxyMe status_code: {status_code}")
|
||||
return True
|
||||
else:
|
||||
print(error)
|
||||
logging.error(f"open ProxyMe error: {error}")
|
||||
return False
|
||||
|
||||
def click_allow(device):
|
||||
output, status_code, error = run_adb_command(['adb', '-s', device, 'shell', 'input', 'tap', '540', '1170'])
|
||||
if status_code == 0:
|
||||
logging.info(f"click allow status_code: {status_code}")
|
||||
return True
|
||||
else:
|
||||
print(error)
|
||||
logging.error(f"click allow error: {error}")
|
||||
return False
|
||||
|
||||
def restart_ProxyMe(device):
|
||||
if stopAutojs(device):
|
||||
if clearCache(device):
|
||||
if openProxyMe(device):
|
||||
time.sleep(3)
|
||||
logging.info("restart_ProxyMe: wait 3 s")
|
||||
if click_allow(device):
|
||||
print(f"restart ProxyMe Success")
|
||||
return True
|
||||
else:
|
||||
print(f"click allow failed")
|
||||
return False
|
||||
else:
|
||||
print(f"open ProxyMe failed")
|
||||
return False
|
||||
else:
|
||||
print(f"clear cache failed")
|
||||
return False
|
||||
else:
|
||||
print(f"stop autojs failed")
|
||||
return False
|
||||
28
modules/device.py
Normal file
28
modules/device.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
def run_adb_command(command_list):
|
||||
process = subprocess.Popen(command_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = process.communicate()
|
||||
output = stdout.decode().strip()
|
||||
status_code = process.returncode
|
||||
error = stderr.decode().strip()
|
||||
return output, status_code, error
|
||||
|
||||
def get_adb_devices():
|
||||
try:
|
||||
output = subprocess.check_output(['adb', 'devices'])
|
||||
# 将输出解码为字符串,并按换行符拆分成行
|
||||
lines = output.decode().strip().split('\n')
|
||||
|
||||
# 获取连接的设备列表(排除标题行)
|
||||
devices = [line.split('\t')[0] for line in lines[1:]]
|
||||
# print(devices)
|
||||
print(f"连接的adb设备数:{len(devices)}")
|
||||
return devices
|
||||
except subprocess.CalledProcessError:
|
||||
logging.info(f"get_adb_devices: ")
|
||||
# 处理如果adb命令未找到或运行错误的情况
|
||||
return []
|
||||
|
||||
|
||||
64
modules/fileRW.py
Normal file
64
modules/fileRW.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
def read_last_n_lines(n):
|
||||
file_path = './cache/record.txt'
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
lines = file.readlines()
|
||||
last_n_lines = [line.rstrip() for line in lines[-n:]]
|
||||
logging.info(f"read_last_n_lines:last_{n}_lines={last_n_lines} ")
|
||||
return last_n_lines
|
||||
except FileNotFoundError:
|
||||
logging.error(f"read_last_n_lines error: 文件未找到或路径错误。")
|
||||
print("文件未找到或路径错误。")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def generate_json_data(lines):
|
||||
# 生成包含时间信息的 JSON 数据
|
||||
data = {
|
||||
'time': {}
|
||||
}
|
||||
for i, line in enumerate(lines, 1):
|
||||
data['time'][str(i)] = line
|
||||
json_data = json.dumps(data)
|
||||
return json_data
|
||||
|
||||
|
||||
def delete_file(file_path):
|
||||
try:
|
||||
# 检查文件是否存在
|
||||
if os.path.exists(file_path):
|
||||
# 确保文件已关闭
|
||||
with open(file_path, "a"):
|
||||
pass
|
||||
# 删除文件
|
||||
os.remove(file_path)
|
||||
logging.info(f"文件 {file_path} 已成功删除!")
|
||||
print(f"文件 {file_path} 已成功删除!")
|
||||
else:
|
||||
logging.info(f"文件 {file_path} 不存在,无法删除!")
|
||||
print(f"文件 {file_path} 不存在,无法删除!")
|
||||
except Exception as e:
|
||||
logging.error(f"delete_file error: {e}")
|
||||
print(f"删除文件时出现错误:{e}")
|
||||
|
||||
|
||||
def write_error_devices(text, newline=True):
|
||||
filename = "./error_devices.txt"
|
||||
|
||||
# 判断当前目录下是否有txt文件
|
||||
if not os.path.exists(filename):
|
||||
# 如果文件不存在,则新建并写入文本
|
||||
with open(filename, "w") as file:
|
||||
file.write(text)
|
||||
else:
|
||||
# 如果文件已存在,则在文件末尾追加文本,并换行(如果需要)
|
||||
with open(filename, "a") as file:
|
||||
if newline:
|
||||
file.write("\n" + text)
|
||||
else:
|
||||
file.write(text)
|
||||
18
modules/read_config.py
Normal file
18
modules/read_config.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import configparser
|
||||
|
||||
def read_config_ini():
|
||||
file_path = './config.ini'
|
||||
config = configparser.ConfigParser()
|
||||
config.read(file_path)
|
||||
cache_file_path = config.get("Cache","cache_file_path")
|
||||
# 读取数据库配置信息
|
||||
database_config = {
|
||||
'host': config.get('Database', 'host'),
|
||||
'username': config.get('Database', 'username'),
|
||||
'password': config.get('Database', 'password'),
|
||||
'database_name': config.get('Database', 'database_name')
|
||||
}
|
||||
print(database_config)
|
||||
# return cache_file_path,database_config
|
||||
return cache_file_path
|
||||
|
||||
Reference in New Issue
Block a user