1、Script--->Start Recording Script,进行登录脚本录制;

2、当脚本录制完成后,Script--->Stop Recording Script,停止脚本录制,并保存录制的脚本,以*.vbs保存;

3、Options--->Session Options--->Logon Actions,选中Logon script,然后导入刚才录制的脚本*.vbs

1.  autologin.vbs

#$language ="VBScript"
#$interface ="1.0"
Sub main
   crt.Screen.Synchronous =True

crt.Screen.WaitForString "Login UserID: "
   crt.Screen.Send "humpic"& VbCr
   crt.Screen.WaitForString "Login Password: "
   crt.Screen.Send "123456"& VbCr

crt.Screen.Synchronous =False
End Sub

2. CMD

SecureCRT.EXE   /SCRIPT autologin.vbs /telnet 127.0.0.1 23

securecrt.exe /SSH2 /L root /P 22 /PASSWORD root 127.0.0.1

最常用的ActiveX script引擎有VBScript和JScript,都是微软的东东,所以SecureCRT支持这两种脚本语言。脚本的头部指定脚本与接口类型,脚本内容以main函数作为执行入口

一、脚本头部及主函数

# $language = "VBScript" 或 # $language = "JScript" 或 # $language = "Python"

# $interface = "1.0"

Sub Main 或 function main() { 或 def main():

.....

End Sub  }  main()

说明:

脚本头部

language:SecureCRT使用的脚本引擎,若为JavaScript则language = "JScript"

interface:SecureCRT的接口版本

Python:需SecureCRT6.6以上才支持。

主函数

Sub Main

' Display SecureCRT's version

MsgBox "SecureCRT version is: " & crt.Version

condition = DoSomething()

If condition = 0 Then

' Error, bailout

Exit Sub

End If

End Sub

二、SecureCRT内置对象

SecureCRT提供了内置对象与脚本交互,这些对象封装了属性与操作,可用来操纵程序行为。其中crt是顶级对象,代表了SecureCRT进程,其属性有ActivePrinter(打印机),Dialog,Screen,Session(会话),Version,Window(窗口)这些二级对象,操作有Sleep,Quit

1.Screen操作屏幕的输入输出

要注意的是,Screen只代表客户区的可见部分,这部分的大小可以通过会话选项里的逻辑行、列数来设定。而整个会话的输出记录是回滚区,没有对应的对象;

属性:

CurrentColumn,CurrentRow(当前光标所在逻辑行)

因为逻辑行、列数限定了可见区的大小,所以当输出满屏时,CurrentRow和Rows的值其实是一样的,都是最大值,不会随着屏幕输出再改变,这种设计实在是有些egg hurt,不知能否通过设置来解决

Columns,Rows(可见区中的输出行数)

Synchronous(同步模式,据说为了避免某些情况下的数据丢失,建议开启)。

crt.Screen.Synchronous = True

crt.Screen.Synchronous = False

操作:

Clear 清掉所有输出,包括回滚与提示符,直接变白板;

crt.Screen.Clear

Get 获取某个矩形区域内的输出文本,用行列数当坐标来指定;

crt.Screen.Get(row1, col1, row2, col2)

Get2获取指定两行间的输出文本

crt.Screen.Get2(row1, row2)

ReadString获得命令的执行输出

char = crt.Screen.ReadString()

Send发送命令字符串(包括换行符);

crt.Screen.Send "ps -ef|grep AppServer|grep -v grep" & vbCr

SendSpecial用来发送SecureCRT的一些内置命令,如键映射

screen.SendSpecial "MENU_PASTE"

screen.SendSpecial "TN_BREAK"

screen.SendSpecial "VT_PF1"

除了WaitForStrings,其它均返回布尔值

WaitForString等待输出某字符串,支持超时;

WaitForStrings多个字符串中任何一个;

index = crt.Screen.WaitForStrings("#" , ">" , 10)

返回值为为字符串的索引,从1开始,超时则返回0。

WaitForCursor等待光标移动,

WaitForKey等待任意键按下,

2.Session提供当前会话接口。

属性:

Connected当前会话是否连接,返回bool值

LocalAddress返回本PC机IP

RemoteAddress返回会话IP

RemotePort返回会话端口

LogFileName:设置或返回当前会话日志目录

Logging:是否开启日志,返回bool值

Path:当前会话开始的ini配置文件地址

操作:

Connect连接会话;

crt.Screen. Connect arg

crt.session.Connect("/s mysession") ‘直接连接会话

crt.Session.Connect("/TELNET 214.25.28.25 23")  ‘telnet 23号端口

cmd = "/ssh2 /L " & user &" /PASSWORD " & pwd & " /C 3DES " & ip
crt.Session.Connect cmd
/S session_name:开始SecureCRT并打开会话连接。
/SSH1 [ssh_options] hostname:以SSH1协议打开hostname连接。
[/C cipher]标识加密技术,默认3DES;其他有NONE, DES, 3DES, RC4 and BLOWFISH
[/I identityfile]Specifies the location of the user's identity file. The identity file contains the private key needed to connect to the server using RSA authentication. The absence of this option causes password authentication to be used.
[/L username]用户名
[/P port]端口,默认22
[/PASSWORD password]密码
[/Z compressionlevel]密码压缩级别,1-9
/SSH2 [ssh_options] hostname:以SSH2协议打开hostname连接。
[/AUTH method]指定连接SSH2时的认证方法,多种方法用逗号隔开。
 i.e., /AUTH password,publickey,keyboard-interactive,gssapi
[/C cipher]标识加密技术,默认3DES;其他有NONE, 3DES, RC4 and TWOFISH
[/I identityfile]Specifies the location of the user's identity file. The identity file contains the private key needed to connect to the server using RSA authentication. The absence of this option causes password authentication to be used.
[/L username]用户名
[/LOCAL port:hostname:hostport]Forwards connection requests from port (on localhost) to hostport on hostname.
[/M MAC]指定消息认证码
[/P port]端口,默认22
[/PASSPHRASE passphrase]Logs on to the SSH2 server using passphrase as the passphrase for the identity file given with the /I option.
[/PASSWORD password]密码
[/REMOTE port:hostname:hostport]Forwards connection requests from port (on localhost) to hostport on hostname.
Requests the SSH2 server to accept connection requests on port (on the remote machine) and forward the requests to hostport on hostname
[/Z compressionlevel]密码压缩级别,1-9
/TELNET hostname [port]:开始SecureCRT并以Telnet协议打开hostname连接。
/RLOGIN hostname:以Rlogin协议打开hostname连接。
[/L username]用户名
/TAPI phone number:开始SecureCRT并以TAPI协议打开会话连接。
/SERIAL port:以port打开默认会话。

Disconnect断开会话;

crt.Session.Disconnect

Log启用或禁用日志;

crt.Session.Log(start[,append,[raw]]) ‘参数均为bool变量,默认false

3.Dialog提供了输入框和MessageBox

Prompt:提示用户输入

crt.Dialog.Prompt(message [, title [, default [, isPassword ]]])
Dim pass
pass = crt.Dialog.Prompt("Enter your password:", "Logon Script", "", True)
MessageBox:显示信息
crt.Dialog.MessageBox(message [, title [, buttons]])
' button 参数选项
Const ICON_STOP = 16 ' display the ERROR/STOP icon.
Const ICON_QUESTION = 32 ' display the '?' icon
Const ICON_WARN = 48 ' display a '!' icon.
Const ICON_INFO= 64 ' displays "info" icon.
Const BUTTON_OK = 0 ' OK button only
Const BUTTON_CANCEL = 1 ' OK and Cancel buttons
Const BUTTON_ABORTRETRYIGNORE = 2 ' Abort, Retry, and Ignore buttons
Const BUTTON_YESNOCANCEL = 3 ' Yes, No, and Cancel buttons
Const BUTTON_YESNO = 4 ' Yes and No buttons
Const BUTTON_RETRYCANCEL = 5 ' Retry and Cancel buttons
Const DEFBUTTON1 = 0 ' First button is default
Const DEFBUTTON2 = 256 ' Second button is default
Const DEFBUTTON3 = 512 ' Third button is default
' MessageBox() 的返回值
Const IDOK = 1 ' OK button clicked
Const IDCANCEL = 2 ' Cancel button clicked
Const IDABORT = 3 ' Abort button clicked
Const IDRETRY = 4 ' Retry button clicked
Const IDIGNORE = 5 ' Ignore button clicked
Const IDYES = 6 ' Yes button clicked
Const IDNO = 7 ' No button clicked
' 例子
result = crt.Dialog.MessageBox("Login Failed, Retry?", "Error", ICON_QUESTION Or BUTTON_YESNO Or DEFBUTTON2 )
If result = IDNO Then
Exit Sub
End If

4.Window:窗口

属性:

lActivate:标识当前SecureCRT窗口是否激活,返回bool值

lCaption:设置或返回SecureCRT窗口的标题

lState:返回SecureCRT窗口的显示状态。

0 - hidden

1 - visible (normal)

2 - minimized

3 - maximized

操作:

Activate:激活SecureCRT窗口,置于桌面最顶层

Show:各种状态显示SecureCRT窗口。

0 - hidden

1 - visible (normal)

2 - minimized

3 - maximized

如果脚本不需要交互的话,可以设置crt.show 0,隐藏窗口执行

5. Arguments:参数

访问参数,参数通过/ARG命令行传递。' CRT.exe /ARG myhostname /ARG 5555

属性:

Count:传递给SecureCRT的参数个数。

crt.Arguments.Count

操作:

GetArg:激活SecureCRT,置于桌面最顶层

crt.Arguments.GetArg(number) ‘number从0开始

crt.Arguments(number)

三、SecureCRT6.6新增对象

相比5.1,crt多了些对象属性:Arguments(命令行参数),Clipboard(剪贴板),FileTransfer,操作上则添加了tab操作(标签页属性)和加强了错误处理(处理脚本出错但继续执行的情况),GetScriptTab比较常用,用来获得执行脚本所在的tab对象。其下的二级对象也加了不少属性和操作

object.Get2(row1, col1, row2, col2),和Get的参数一个样。看描述,Get获取的的是矩形区域内的文本,空白也被包括,而Get2会根据换行\r\n来判断行文本是否已结束,换行也被包括

ReadString非常有用,可用来获得命令的执行输出,惯用法:

1)char = crt.Screen.ReadString()  //无参式,从输出中一次取一个字符

2)str = crt.Screen.ReadString(StringToWaitFor, TimeOutSeconds)  //超时可省略

3)str = crt.Screen.ReadString(["home", "work"], 10)  // [stringarray],类似WaitForStrings

四、SecureCRT应用程序运行选项

cmd = "SecureCRT.EXE /Script c:\test.vbs /arg 129.0.31.27 /arg zxiptv"

Shell cmd, 1

命令行运行选项参数:

/ARG argumnet:SecureCRT运行参数

/SCRIPT filename:SecureCRT运行脚本。

/COLOR_SCHEME scheme:Specifies an existing color scheme A combination of session settings that specify a variety of colors associated with the terminal window, including foreground and background. to be used for the session A session is a set of options that are assigned to a connection to a remote machine. These settings and options are saved under a session name and allow the user to have different preferences for different hosts. being started. When this switch is used, any changes to the session color scheme will be ignored. If a nonexistent scheme is specified, the session configuration color scheme will be used.

/F folderpathname:Points to an alternate configuration folder location. If there is no configuration file in the alternate folder, SecureCRT will create one. Without this option, SecureCRT will use the configuration information in the default folder location.

/FIREWALL:Connects session using current global firewall settings. Replaces /PROXY and /SOCKS options.

/MAX_COLS n:SecureCRT最大列数,范围,132—1024

/NOMENU:隐藏菜单栏

/NOTOOLBAR:隐藏工具栏

/NOSAVE:设置不保存

/POS x y:SecureCRT窗口位置

/TITLEBAR "Title to display":Sets the text in the title bar to the string given as argument.

转载于:https://blog.51cto.com/7090376/1359528

SecureCRT录制和添加自动登录脚本相关推荐

  1. python登录脚本_selenium+python实现自动登录脚本

    os:windows 前提:Python,selenium,IEDriverServer.exe,ie浏览器 首先安装Python2.7 安装成功后,计算机联网状态下在cmd命令行下输入:pip in ...

  2. python 自动化输入登录密码_selenium+python实现自动登录脚本

    os:windows 前提:Python,selenium,IEDriverServer.exe,ie浏览器 首先安装Python2.7 安装成功后,计算机联网状态下在cmd命令行下输入:pip in ...

  3. WinForm中给DataGridView添加 自动编号

    //实现功能 DataGridView 添加 自动编号 DataTable table = DataTable(); DataColumn column = DataColumn(); Column. ...

  4. monkeyrunner自动登录脚本

    自己写了个平时测试的app的自动登录脚本,亲测可运行.读者参照时只需要改包名.activity名称.坐标值.账号和密码即可 查看坐标是多少的方法:使用手机的指针位置来实现:系统设置---开发者选项-- ...

  5. 分布式监控系统Zabbix3.2添加自动发现磁盘IO并注册监控

     zabbix并没有给我们提供这么一个模板来完成在Linux中磁盘IO的监控,所以我们需要自己来创建一个,在此还是在Linux OS中添加. 由于一台服务器中磁盘众多,如果只一两台可以手动添加,但服务 ...

  6. expect详解及自动登录脚本的实现

    expect可以让一些交互的任务自动完成,我们可以将一些交互过程写入脚本,ssh登录就是一个简单的实现,下面将介绍expect的用法. 1 安装 yum install -y expect 2 语法介 ...

  7. brew 无法安装iterm2_Mac安装sshpass 替代spawn自动登录脚本(解决rz sz问题)

    Mac安装sshpass 替代spawn自动登录脚本(解决rz sz问题) 很早前就发现 如果通过 spawn 脚本去登录 服务器,那么 rz sz 指令是无法使用的,具体为什么,网上说就是不支持!. ...

  8. 抖音app开发时,在录制视频添加背景音乐功能实现流程

    抖音app之所以"横扫"整个短视频领域,最主要的还是占据了短视频玩法的"先机",其中在录制视频时添加背景音乐,是很多用户都非常喜欢的步骤,但是在抖音app开发时 ...

  9. 短视频开发,录制视频添加背景音乐功能实现

    短视频开发,会在视频录制时提供相关的背景音乐选择,看似简单的选取背景音乐,但对开发人员来说却不是那么简单,如何实现短视频开发录制视频添加背景音乐功能呢? 1.短视频开发在录制界面点击音乐,绘制UI 添 ...

最新文章

  1. BH60绝对位置旋转编码器编程资料
  2. Picasso:开启大前端的未来
  3. 如何在VB例程中接收自定义消息
  4. JS基础篇--函数声明与定义,作用域,函数声明与表达式的区别
  5. Linux运维学习大纲
  6. web安全之XSS基础-常见编码科普
  7. list多选 android,Android ExpandableListView单选以及多选实现代码
  8. git 简单使用 基本操作
  9. Java多线程11:ReentrantLock的使用和Condition
  10. 领秀加速器软件介绍及功能介绍
  11. 4K 对齐与固态硬盘检测工具
  12. ADAMS 脚本仿真
  13. Chrome浏览器误删书签恢复
  14. Linux文件归档与压缩命令
  15. 德莱联盟(判断两个线段是否相交)
  16. 运筹说 第50期 | 图解法与单纯形法解目标规划
  17. vscode/typora+picGo-core(命令行CLI)/picGo(GUI)+图片上传(github/smms)/批量上传/typora语法扩展渲染功能设置/修改本地图片存放位置配置
  18. 获取各大电商平台,item_get_app - 获得淘宝app商品详情原数据API返回数据说明
  19. 猫咪突然嘴巴合不住是怎么回事?
  20. 【ORACLE】从安装ORACLE LINUX 8开始构建一个ORACLE21C的docker镜像

热门文章

  1. -中高级前端必须注意的40条移动端H5坑位指南 | 网易三年实践
  2. Android 通过AccessibilityService实现微信聊天记录导出
  3. 那些害惨我们的伪科学(下)
  4. 嘿,你的手机里有个人工智能芯片等待查收!
  5. [转帖]叶开:Siebel中国之路三部曲(三)
  6. 擎天柱和好朋友的故事:MIT让机器人团结友爱互相传授技能
  7. 【C++】课节笔记及梳理总结---EP2
  8. 清洁机器人之音频方案 ISD2360 开发总结1
  9. 关于冒号和双冒号用法
  10. html5视频播放器原理,HTML5 - 两款基于JS的视频播放器的使用说明(VideoJS和jPlayer)...