python批量修改xshell保存的密码
下面的脚本会在标签目录下生成out文件夹,将新标签保存进去。
import os
curr_pwd= "Password=*****==" #找到xsh保存的路径下打开现有的文件查看密码
update_pwd = "Password=******==\n"
path = input('请输入xsh文件路径:') #输入xsh保存的路径
for root, dirs, files in os.walk(path):
for f1 in files:
if '.xsh' in f1: #判断为xsh文件
with open(path +'\\'+ f1,encoding='utf-16') as f: #xsh文件编码为utf16
if not os.path.exists(path+'\\out'): # 是否存在out文件夹
os.makedirs(path+'\\out') # 如果没有则创建
fw = open(path+'\\out' +'\\'+ f1, 'w',encoding='utf-16')
for line in f.readlines(): #遍历文件中每一行
print(line)
if curr_pwd in line:
print(curr_pwd)
fw.write(update_pwd)
else:
fw.write(line)
print('修改完成')
该脚本使用Python实现批量修改XShell保存的密码功能。用户输入XSH文件路径后,脚本会遍历所有.xsh文件,将旧密码替换为新密码,并将更新后的文件保存到out文件夹。此过程适用于需要统一更改多个XShell连接密码的场景。
909

被折叠的 条评论
为什么被折叠?



