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 路径
    CRT_Path(path)

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值