secueCRT脚本小试牛刀
secureCRT可以使用脚本自动化执行操作,如登录脚本。支持vbs、python(6.6以上版本才支持python,且目前最高仅支持python 3.9)和jscript。据说还可以录制操作,没试过。secureCRT版本为9.10。
secureCRT内置了一些对象,入crt,具体用法可见官网Automation Academy、帮助,或其他网上资料。
尝试了vbs和python,功能一样:
#$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True Sub Main if crt.Arguments.Count <1 Then exit sub End If crt.Screen.WaitForString "[ 0 ]" crt.Screen.Send "/" & crt.Arguments(0) & vbcr 'ip unicodeChar11 = ChrW(&H624B) unicodeChar12 = ChrW(&H52A8) unicodeChar13 = ChrW(&H8F93) unicodeChar14 = ChrW(&H5165) inputText = unicodeChar11 & unicodeChar12 & unicodeChar13 & unicodeChar14 crt.Screen.WaitForString ChrW(&H8FD4) & ChrW(&H56DE) i = 0 quit = false bracketContent = "0" do str = crt.Screen.Get(i,0,i,20) i = i+1 If InStr(str, inputText) > 0 Then start = InStr(str, "[") endPos = InStr(start + 1, str, "]") bracketContent = Mid(str, start + 1, endPos - start - 1) 'crt.Dialog.MessageBox(bracketContent) End If If InStr(str, "[ r ]") > 0 Then quit=true End If loop until quit=true crt.Screen.Send bracketContent & vbcr If crt.Arguments.Count >=2 Then crt.Screen.Send crt.Arguments(1) & vbcr Else exit sub End If 'Set WshShell = CreateObject("WScript.Shell") 'crt.Screen.Send WshShell.ExpandEnvironmentStrings("%PASSWD%") & vbcr If crt.Arguments.Count >=3 Then crt.Screen.Send crt.Arguments(2) & vbcr Else exit sub End If End Sub
#$language = "Python" #$interface = "1.0" crt.Screen.Synchronous = True def Main(): if crt.Arguments.Count<1: return crt.Screen.WaitForString("[ 0 ]") crt.Screen.Send("/" + crt.Arguments[0] + "\n") strSDSR = chr(0x624B) + chr(0x52A8) + chr(0x8F93) + chr(0x5165) strFH = chr(0x8FD4) + chr(0x56DE) crt.Screen.WaitForString(strFH) i = 0 quit = False bracketContent = "0" while True: str = crt.Screen.Get(i,0,i,20) i = i+1 if str.find(strSDSR)>0: crt.Dialog.MessageBox(str) start=str.find("[") end=str.find("]") bracketContent = str[start + 1:end] #crt.Dialog.MessageBox(bracketContent) if str.find("[ r ]") > 0: break crt.Screen.Send(bracketContent+"\n") if crt.Arguments.Count >=2: crt.Screen.Send(crt.Arguments[1]+"\n") if crt.Arguments.Count >=3: crt.Screen.Send(crt.Arguments[2]+"\n") Main()