欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

xshell會話批量遷移到mobaxterm的工具(python小工具)

 更新時間:2021年12月20日 15:41:37   作者:韓曉萌  
這篇文章主要介紹了xshell會話批量遷移到mobaxterm的工具,使用方法也超級簡單,本文通過python代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

自己寫了一個Python小工具:xshell2mobaxterm,可以將xshell的session轉(zhuǎn)換成mobaxterm的數(shù)據(jù)文件以導(dǎo)入到mobaxterm中。

exe版的編譯好了,博客園不支持附件,所以沒法上傳,需要的話可以評論留下郵箱,我發(fā)送給你。

Python代碼:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# xshell session to mobaxterm session file
# Support: TELNET, serial, SSH
# Usage: xshell2mobaxterm.py Xshell_Session_Direcotry
# Example: python3 xshell2mobaxterm.py D:\Xshell\Session >mobaxterm.mxtsessions
# Linux platform enviroment: LANG=zh_CN.utf8/en_US.utf8
# Windows: python3.6 cmd run it.

import os, sys


def convert_x2m(xshell_session_file, num):
    #print(xshell_session_file)
    ssh_format = (
        '[{BookMarks}]\n'
        'SubRep={Directory}\n'
        'ImgNum=41\n'
        '{SessionName} ({UserName})=#109#0%{Host}%{Port}%{UserName}%%-1%-1%%%%%0%0%0%%%-1%0%0%0%%1080%%0%0%1#DejaVu Sans Mono%{FontSize}%0%0%-1%15%236,236,236%30,30,30%180,180,192%0%-1%0%%xterm%-1%-1%_Std_Colors_0_%80%24%0%1%-1%<none>%%0%1%-1#0# #-1\n'
    )
    
    telnet_format = (
        '[{BookMarks}]\n'
        'SubRep={Directory}\n'
        'ImgNum=41\n'
        '{SessionName} ()= #98#1%{Host}%{Port}%%%2%%%%%0%0%%1080%#DejaVu Sans Mono%{FontSize}%0%0%-1%15%236,236,236%30,30,30%180,180,192%0%-1%0%%xterm%-1%-1%_Std_Colors_0_%80%24%0%1%-1%<none>%%0%1%-1#0# #-1\n'
    )
    
    serial_format = (
        '[{BookMarks}]\n'
        'SubRep={Directory}\n'
        'ImgNum=42\n'
        '{SessionName}= #131#8%-2%100{Speed}%3%0%0%1%2%{Port}#DejaVu Sans Mono%{FontSize}%0%0%-1%15%236,236,236%30,30,30%180,180,192%0%-1%0%%xterm%-1%-1%_Std_Colors_0_%80%24%0%1%-1%<none>%%0%1%-1#0# #-1\n'
    )

    session_file = open(xshell_session_file, 'r')
    session_lines = session_file.readlines()
    xshell_attr = {'num': num}
    xshell_attr['Directory'] = os.path.dirname(xshell_session_file.replace(sys.argv[1], '').strip('\\'))
    xshell_attr['SessionName'] = os.path.basename(xshell_session_file).rsplit('.',1)[0]

    if num == 0:
        xshell_attr['BookMarks'] = 'Bookmarks'
    else:
        xshell_attr['BookMarks'] = 'Bookmarks_{num}'.format(num=num)

    for line in session_lines:
        if line.startswith('UserName='):
            xshell_attr['UserName'] = line.split('=')[1].strip('\n')
        elif line.startswith('Port='):
            xshell_attr['Port'] = line.split('=')[1].strip('\n')
        elif line.startswith('FontSize='):
            xshell_attr['FontSize'] = line.split('=')[1].strip('\n')
        elif line.startswith('Host='):
            xshell_attr['Host'] = line.split('=')[1].strip('\n')
        elif line.startswith('Protocol='):
            xshell_attr['Protocol'] = line.split('=')[1].strip('\n')
        elif line.startswith('BaudRate='):
            xshell_attr['Speed'] = line.split('=')[1].strip('\n')

    #print(xshell_attr)
    x = 1
    if xshell_attr.get('Protocol').lower().startswith('ssh'):
        x = ssh_format.format(
            Directory = xshell_attr.get('Directory') or '',
            SessionName = xshell_attr.get('SessionName') or 'default',
            UserName = xshell_attr.get('UserName') or '',
            Port = xshell_attr.get('Port') or '22',
            FontSize = xshell_attr.get('FontSize') or '12',
            num=xshell_attr['num'],
            Host=xshell_attr.get('Host') or '',
            BookMarks=xshell_attr['BookMarks']
        )
    elif xshell_attr.get('Protocol').lower() == 'telnet':
        x = telnet_format.format(
            Directory = xshell_attr.get('Directory') or '',
            SessionName = xshell_attr.get('SessionName') or 'default',
            UserName = xshell_attr.get('UserName') or '',
            FontSize = xshell_attr.get('FontSize') or '12',
            Port = xshell_attr.get('Port') or '23',
            num=xshell_attr['num'],
            Host=xshell_attr.get('Host') or '',
            BookMarks=xshell_attr['BookMarks']
        )
    elif xshell_attr.get('Protocol').lower() == 'serial':
        x = serial_format.format(
            Directory = xshell_attr.get('Directory') or '',
            SessionName = xshell_attr.get('SessionName') or 'default',
            FontSize = xshell_attr.get('FontSize') or '12',
            Port = xshell_attr.get('Port') or '',
            Speed = xshell_attr.get('Speed') or '9600',
            num = xshell_attr['num'],
            BookMarks = xshell_attr['BookMarks']
        )
    #print(x.replace('/', '\\'))
    return x.replace('/', '\\')


def generate_mobaxterm_sessions(xshell_session_path, count):
    #print(session_path)
    base_dir = os.listdir(xshell_session_path)
    for file in base_dir:
        file = os.path.join(xshell_session_path, file)
        try:
            os.listdir(file)
            #print(file)
            generate_mobaxterm_sessions(file, count)
        except:
            if not file.endswith('.xsh'): continue
            print(convert_x2m(file, count[0]))
            count[0] += 1

if __name__ == '__main__':
    count = [0]
    generate_mobaxterm_sessions(sys.argv[1], count)

使用方法:

(1)cmd>python3 Python代碼文件 "Xshell Session所在的路徑" >mobaxterm.mxtsessions

例如:C:\Users\user>python3 xshell2moba.py "C:\Users\user\Documents\NetSarang\Xshell\Sessions" > mobaxterm.mxtsessions

會在cmd的當(dāng)前目錄(C:\Users\user\)中生成一個mobaxterm.mxtsessions文件

備注:如果不知道Xshell Session的路徑,可以在xshell本地命令行中輸入pwd命令查看:

(32)將生成的mobaxterm.mxtsessions文件導(dǎo)入mobaxterm即可。

到此這篇關(guān)于xshell會話批量遷移到mobaxterm的工具的文章就介紹到這了,更多相關(guān)xshell會話遷移mobaxterm工具內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python實現(xiàn)輸入數(shù)字的連續(xù)加減方法

    python實現(xiàn)輸入數(shù)字的連續(xù)加減方法

    今天小編就為大家分享一篇python實現(xiàn)輸入數(shù)字的連續(xù)加減方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • 探究Python的Tornado框架對子域名和泛域名的支持

    探究Python的Tornado框架對子域名和泛域名的支持

    這篇文章主要介紹了探究Python的Tornado框架對子域名和泛域名的支持,Tornado作為一個典型的異步框架、在Python開發(fā)者中的人氣相當(dāng)高,需要的朋友可以參考下
    2015-05-05
  • Python3使用requests發(fā)閃存的方法

    Python3使用requests發(fā)閃存的方法

    requests是一個python 輕量的http客戶端庫,相比python的標(biāo)準(zhǔn)庫要優(yōu)雅很多。接下來通過本文給大家介紹Python3使用requests發(fā)閃存的方法,感興趣的朋友一起學(xué)習(xí)吧
    2016-05-05
  • Python簡單爬蟲導(dǎo)出CSV文件的實例講解

    Python簡單爬蟲導(dǎo)出CSV文件的實例講解

    今天小編就為大家分享一篇Python簡單爬蟲導(dǎo)出CSV文件的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • Pandas Shift函數(shù)的基礎(chǔ)入門學(xué)習(xí)筆記

    Pandas Shift函數(shù)的基礎(chǔ)入門學(xué)習(xí)筆記

    shift函數(shù)是對數(shù)據(jù)進(jìn)行移動的操作,下面這篇文章主要給大家介紹了關(guān)于Pandas Shift函數(shù)的基礎(chǔ)入門學(xué)習(xí)筆記,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-11-11
  • 使用tensorflow實現(xiàn)AlexNet

    使用tensorflow實現(xiàn)AlexNet

    這篇文章主要為大家詳細(xì)介紹了使用tensorflow實現(xiàn)AlexNet,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Python中os模塊功能與用法詳解

    Python中os模塊功能與用法詳解

    這篇文章主要介紹了Python中os模塊功能與用法,總結(jié)分析了Python os模塊基本功能、內(nèi)置函數(shù)、使用方法及相關(guān)操作注意事項,需要的朋友可以參考下
    2020-02-02
  • Python3.5面向?qū)ο笈c繼承圖文實例詳解

    Python3.5面向?qū)ο笈c繼承圖文實例詳解

    這篇文章主要介紹了Python3.5面向?qū)ο笈c繼承,結(jié)合圖文與實例形式詳細(xì)分析了Python3.5面向?qū)ο笈c繼承的相關(guān)概念、原理、實現(xiàn)方法及操作注意事項,需要的朋友可以參考下
    2019-04-04
  • python實現(xiàn)記事本功能

    python實現(xiàn)記事本功能

    這篇文章主要為大家詳細(xì)介紹了python實現(xiàn)記事本功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • Python實用技巧之臨時文件的妙用

    Python實用技巧之臨時文件的妙用

    當(dāng)我們用Python編寫程序時,有時候需要臨時存儲數(shù)據(jù)且不希望占用多少內(nèi)存,這些情況下以創(chuàng)建臨時文件的方式進(jìn)行處理,既不會干擾本地文件系統(tǒng),又安全省事。本文主要介紹了臨時文件的一些妙用,希望大家能夠喜歡
    2023-02-02

最新評論