ios-hooks/modify_config.py
2025-11-18 14:52:09 +08:00

62 lines
1.7 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 paramiko
import os
import plistlib
# 设置SSH连接参数
# hostname = '172.30.104.18'
port = 22
username = 'root'
password = 'alpine'
# packagename = 'com.funny.prank.call'
def moveRemote(hostname:str, name:str,pkg:str, serverurl:str, wash:bool=False):
# 创建SSH传输通道
transport = paramiko.Transport((hostname, port))
transport.set_keepalive(5)
# 连接SSH服务端以用户名和密码进行认证
transport.connect(username=username, password=password)
# 创建SFTP客户端
sftp = paramiko.SFTPClient.from_transport(transport)
# 上传本地文件到远程主机
local_path = 'local_file.txt'
remote_path = '/User/OhNoData/config001.plist'
# sftp.put(local_path, remote_path)
sftp.get(remote_path, local_path)
with open(local_path, 'rb') as fp:
configPlist = plistlib.load(fp)
configPlist['IpDevName'] = name
configPlist['ServerURL'] = serverurl
configPlist['PackageName'] = pkg
configPlist['WashParam'] = wash
configPlist['MainServerURL'] = "http://192.168.40.8:8080"
with open(local_path, 'wb') as fp:
plistlib.dump(configPlist, fp)
print(configPlist)
# 上传本地文件到远程主机
sftp.put(local_path, remote_path)
# 关闭SFTP连接
sftp.close()
# 关闭SSH传输通道
transport.close()
if __name__ == "__main__":
ips1 = []
with open("./ips.txt", 'r') as f:
ips1 = [i.strip() for i in f.readlines()]
for it in ips1:
try:
print(it)
moveRemote(it,"CineLookStudio", 'com.cineLookStudio.cineLookStudio', "https://nks-api.i.explore-sun.com")
except Exception as e:
print(e)