Xshell And CRT 快速登录脚本
基本思路
- 复制要登陆的IP地址到剪贴板
- 从剪贴板获取IP地址
- 拼接登录命令
- 需要跳板机才能登录的服务器
- 先登录到跳板机
- 再通过ssh 命令登录
获取剪贴板命令
SecureCRT
1
SeverIP = crt.Clipboard.Text
XShell
1
2Set objHTML = CreateObject("htmlfile")
MyIP = objHTML.ParentWindow.ClipboardData.GetData("text")
拼接登录命令
可以直接登录的机器
SecureCRT
1
crt.Session.Connect "/SSH2 /PASSWORD password username@xx.xx.xx.xx", True
XShell
1
xsh.Session.Open("ssh://username:password@xx.xx.xx.xx:port")
需要跳板机才能登录的机器
SecureCRT
1
2
3
4
5
6
7' 先登录跳板机
crt.Session.Connect "/SSH2 /PASSWORD password username@xx.xx.xx.xx", True
' 拼接ssh命令
crt.Screen.Send "ssh username@xxx.xxx.xxx.xxx"
crt.Screen.Send chr(13)
crt.Screen.WaitForString "password:"
crt.Screen.Send MyPwd & chr(13)XShell
1
2
3
4
5
6
7
8' 先登录跳板机
xsh.Session.Open("ssh://username:password@xx.xx.xx.xx:port")
' 拼接ssh命令
xsh.Screen.Send "ssh username@xxx.xxx.xxx.xxx"
xsh.Screen.Send Vbcr
xsh.Screen.WaitForString "password:"
xsh.Screen.Send password
xsh.Screen.Send Vbcr
示例
SecureCRT示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#$language = "VBScript"
#$interface = "1.0"
Sub Main
crt.Screen.Synchronous = True
crt.Session.Connect "/SSH2 /PASSWORD password1 username@xxx.xxx.xxx.xxx", True
MyIp = trim(crt.Clipboard.Text)
MyUserName = "username"
MyPwd = "password2"
crt.Screen.Send "ssh " + MyUserName + "@" + MyIp
crt.Screen.Send chr(13)
crt.Screen.WaitForString "username@" + MyIp + "'s password:"
crt.Screen.Send MyPwd & chr(13)
crt.Sleep 1000
crt.Screen.Send "echo " + MyIP +" Login Success!"
crt.Screen.Send chr(13)
crt.Screen.Synchronous = False
End SubXShell 示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22Sub Main()
xsh.Screen.Synchronous = true
xsh.Session.Open("ssh://username:password1@xxx.xxx.xxx.xxx:port")
xsh.Session.Sleep(1000)
MyUserName = "username"
MyPwd = "password2"
Set objHTML = CreateObject("htmlfile")
MyIP = objHTML.ParentWindow.ClipboardData.GetData("text")
MyIP = trim(MyIP)
xsh.Screen.Send "ssh " + MyUserName + "@" + MyIp
xsh.Screen.Send Vbcr
xsh.Screen.WaitForString "password:"
xsh.Screen.Send MyPwd
xsh.Screen.Send Vbcr
xsh.Session.Sleep 1000
xsh.Screen.Send("echo "+MyIP+" Login Success!")
xsh.Screen.Send Vbcr
xsh.Screen.Synchronous = false
End Sub
总结
VBScript
简介: VBS是基于Visual Basic的脚本语言。VBS的全称是:Microsoft Visual Basic Script Editon.
详情: 见百度百科和维基百科
VBScript百度百科
VBScript wikipedia
思&悟
- 工作中某件事情重复做了十遍以上,要去想是否可以用更快捷的方式去做这件事
- 花几个小时去研究减少重复,增加自动化是值得的
- 对不了解的事情,不要因为不好搞而畏缩,要从以前的做事中去类比,去总结
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Ting723!