最新发现xshell用的有点问题,用moba的话好多会话需要导入,手动比较麻烦,这边参考别人的代码,修改了一下能够正常使用了,本人菜鸟,仅做参考。
参考大佬连接https://github.com/guugle/xshelltoMobaXterm
# -*- coding:utf-8 -*-import codecsimport osimport sysfrom configparser import ConfigParser# 将代码放在Session目录执行以下命令即可 完成转换# python xshelltomoba.py ./Session > xshell.mxtsessions# 只扫描特定文件suffix_name = '.xsh'# 这是密钥路径 请填对应的Session目录keyLocation = "C:Sessions"def joinString(infolist, keyLocation, iconId): fullString = infolist[0] + ' (' + infolist[3] + ')' + "=#" + str(iconId) + "#0%" + infolist[1] + "%" + infolist[2] + "%" + infolist[ 3] + "%%-1%-1%%%%%0%0%0%%%-1%0%0%0%%1080%%0%0%1%%0%%%%0%-1%-1%0#MobaFont%10%0%0%-1%15%236,236,236%30,30,30%180,180,192%0%-1%0%%xterm%-1%0%_Std_Colors_0_%80%24%0%1%-1%%%0%0%-1%0#0# #-1" #这块后面的可以根据自己的moba测试导出 用notepad--打开 修改即可 print(fullString) returndef convertFile(filePath, fileName): config = ConfigParser() config.read_file(codecs.open(filePath, "r", "utf-16")) name = fileName.replace(".xsh", "") ipAddr = config.get("CONNECTION", "Host") port = config.get("CONNECTION", "Port") username = config.get("CONNECTION:AUTHENTICATION", "UserName") infoList = [name, ipAddr, port, username] return infoListdef scanDirs(basePath): global iconId # print('basePath', basePath) iconId = 41 # 图标ID for dirRoot, dirs, dirFiles in os.walk(basePath): if iconId == 41: SubRep = '' else: break print("[Bookmarks]") print("SubRep=%s" % SubRep) print("ImgNum=%d" % iconId) iconId += 1 for fileName in dirFiles: if fileName.endswith(suffix_name): # print(dirRoot,111,os.sep,2222,fileName,333) fileFullName = dirRoot + os.sep + fileName # print(fileFullName) infoList = convertFile(fileFullName, fileName) joinString(infoList, keyLocation, iconId)if __name__ == '__main__': xshellpath = keyLocation scanDirs(xshellpath)