首页 > 代码库 > python批量修改SecureCRT会话密码

python批量修改SecureCRT会话密码

#利用python批量修改SecureCRT 会话密码
# -*- coding:utf-8 -*-
import os,re

def CRT_Path(path,*args,**kwargs):
    for (dirpath, dirnames, filenames) in os.walk(path):
        for file in filenames:
            fullname = os.path.join(dirpath, file)
            f1 = open(fullname,‘r‘,encoding="utf-8")
            alllines = f1.readlines()
            f1.close()
            f2 = open(fullname, ‘w‘,encoding="utf-8")
            pw_r = re.compile(r‘("Password V2"=)(.*)‘)
            if ‘admin‘ in alllines[0]:  # 判断用户名是否是admin(可根据需要修改)
                for eachline in alllines:
                    a = re.sub(pw_r,‘\g<1>‘+admin_pwd,eachline)
                    f2.writelines(a)
            elif ‘root‘ in alllines[0]: #判断用户名是否是root(可根据需要修改),有其他继续添加就行
                for eachline in alllines:
                    a = re.sub(pw_r,‘\g<1>‘+root_pwd,eachline)
                    f2.writelines(a)
            else:
                f2.writelines(alllines)
            f2.close()

if __name__ == ‘__main__‘:
    # admin 密码加密字符串
    admin_pwd = ‘xxooxxoo‘
    # root 密码加密字符串
    root_pwd = ‘xxooxxooxxoo‘
    path = r‘C:\Users\root\Desktop\Sessions‘  # CRT Seesions 路径

github链接地址:

https://github.com/babyshen/Python/blob/master/%E6%89%B9%E9%87%8F%E4%BF%AE%E6%94%B9SecureCRT%E5%AF%86%E7%A0%81.py

本文出自 “baby神” 博客,请务必保留此出处http://babyshen.blog.51cto.com/8405584/1873322

python批量修改SecureCRT会话密码