首页 > 代码库 > SecureCRT中使用VBs脚本自动telnet登陆

SecureCRT中使用VBs脚本自动telnet登陆

查看SecureCRT帮助文档:

Help-> Help Topics->Scripting -> Script Objects Reference -> Session Object

#$language = "VBScript"#$interface = "1.0"crt.Screen.Synchronous = True This automatically generated script may need to be edited in order to work correctly.Sub Main    for i = 0 to 100    crt.Session.Disconnect    crt.Session.Connect("/TELNET 192.168.1.1")    crt.Screen.WaitForString "login:"    crt.Screen.Send "root" & chr(13)    crt.Screen.WaitForString "Password:"    crt.Screen.Send "123456" & chr(13)    crt.Screen.WaitForString "root@server:"     crt.Screen.Send "df" & chr(13)    crt.Screen.WaitForString "root@server:"     crt.sleep 1000    nextEnd Sub

上述脚本也可以把登陆部分放在for循环外面,只是在一台机器上反复执行一条命令隔1秒.

#$language = "VBScript"#$interface = "1.0" crt.Screen.Synchronous = True  This automatically generated script may need to be edited in order to work correctly. Sub Main         Dim i         i = 10         Do While i > 0                   crt.Screen.Send "df" & chr(13)                   crt.Screen.WaitForString "root@server:"                   crt.Screen.Send "echo ok" & chr(13)                   crt.Screen.WaitForString "root@server:"                              crt.Sleep 1000                   i=i-1         LoopEnd Sub

提示符root@ubuntu:~#,可以写成crt.Screen.WaitForString "root@ubuntu:" 
crt.sleep 1000  ‘sleep 1 seconds

也可以自己录制一个脚本:Script-> Start Recording Script,停止,保存,运行即可。

CRT也支持Python,更加灵活。

SecureCRT中使用VBs脚本自动telnet登陆