securtcrt session配置轉xshell的session配置


參數:

1.securtcrt的session目錄

2.一個xshell的模版文件

3.輸出目錄(必須不存在,自動創建)

#!/usr/bin/python
# -*- coding:utf-8 -*-
#轉換secrt的session文件到xshell的session文件
import os
from sys import *

def gen_xshell_session(path, tpl_file, out_session):
    os.mkdir(out_session)
    for f in os.listdir(path):
        print(f)
        fn = path + '/' + f
        if  os.path.isdir(fn):
            od = out_session + '/' + f
            gen_xshell_session(fn, tpl_file, od)
        else:
            if f.startswith('__'):
                continue
            ext = f.find('.ini')
            ip = f[0:ext]
            xshell_cfg_file = out_session + '/' + ip + '.xsh'
            ifn = open(tpl_file, 'r')
            lns = ifn.readlines()
            ifn.close()
            tpl = os.path.basename(tpl_file)
            tpl_n = tpl.find('.xsh')
            tpl_ip = tpl[0:tpl_n]
            ofn = open(xshell_cfg_file, 'w')
            for ln in lns:
                ln = ln.replace(tpl_ip, ip)
                ofn.write(ln)
            ofn.close()






if __name__ == '__main__':
    secrt_session = argv[1]
    xshell_xsh_tpl_file = argv[2]
    xshell_out_session_dir = argv[3]

    gen_xshell_session(secrt_session, xshell_xsh_tpl_file, xshell_out_session_dir)

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM