这是一个包含自动化配置脚本的压缩文件,专门用于从远程服务器或网络上自动获取和配置CRT(C Runtime Toolkit)设置。该工具旨在提高工作效率,减少手动输入错误。
```vbscript
作者:小怪兽怪瘦
Sub Main
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso,file1,line,str1,params
Set fso = CreateObject(Scripting.FileSystemObject)
Set file1 = fso.OpenTextFile(D:\backup\list.txt,ForReading, False)
Do While Not file1.AtEndOfStream <> True
读取每一行
line = file1.ReadLine
分割IP,用户名,密码 特权密码 型号简写(z m h b) 位置
params = Split(line)
ip = params(0)
user = params(1)
password = params(2)
su = params(3)
mode = params(4)
whereis = params(5)
提供日志,修改后面日期即可
crt.session.LogFileName = D:\backup\log\ & ip & _ & whereis & _20190620.txt
crt.session.Log(true)
建立SSH连接
crt.Session.Connect(/SSH2 /L & user & /PASSWORD & password & & ip)
If mode = m Then
m 代表迈普型号
crt.Screen.Send(enable & Chr(13))
crt.Screen.WaitForString(assword:)
crt.Screen.Send(params(3) & Chr(13))
crt.Screen.WaitForString(#)
关闭more提示
crt.Screen.Send more off & chr(13)
crt.Screen.WaitForString #
Set cmdfile = fso.OpenTextFile(D:\backup\cmd-mp.txt,ForReading, False)
Do While Not cmdfile.AtEndOfStream <> True
line2 = cmdfile.ReadLine
crt.Screen.Send(line2 & Chr(13))
crt.Screen.waitForString #
Loop
执行命令集
crt.Screen.Send show running-config & chr(13)
打开more提示
crt.Screen.WaitForString #
crt.Screen.Send(more on & chr(13))
结束操作并断开连接
crt.Screen.waitForString #
crt.Session.Disconnect
End If
If mode = c Then
c 代表思科型号
Do While Not cmdfile.AtEndOfStream <> True
line2 = cmdfile.ReadLine
Select Case mode
Case cisco:
等待字符串>
crt.Screen.WaitForString(>)
发送命令enable
crt.Screen.Send (enable & chr(13))
等待字符串“assword:”
crt.Screen.WaitForString (assword:)
输入特权密码
crt.Screen.Send (params(3) & chr(13))
等待字符串#
crt.Screen.WaitForString(#)
发送命令configure terminal
crt.Screen.Send(configure terminal & Chr(13))
等待字符串config)#
crt.Screen.WaitForString (config)#)
设置VTY线路长度为0
crt.Screen.Send (line vty 0 4 & chr(13))
等待字符串 line)#
crt.Screen.WaitForString(line)#)
发送命令“length 0”
crt.Screen.Send (length 0 & Chr(13))
等待字符串 line)#
crt.Screen.WaitForString(line)#)
返回全局配置模式
crt.Screen.Send(end & chr(13))
等待字符串 #
crt.Screen.WaitForString(#)
执行命令集
Set cmdfile = fso.OpenTextFile (D:\backup\cmd-cisco.txt, ForReading, False)
Do While Not cmdfile.AtEndOfStream <> True
line2 = cmdfile.ReadLine
crt.Screen.Send(line2 & chr(13))
等待字符串 #
crt.Screen.waitForString(#)
Loop
执行命令show running-config
crt.Screen.Send (show running-config & Chr(13))
等待字符串#
crt.Screen.WaitForString(#)
返回全局配置模式并恢复VTY线路长度为默认值
crt.Screen.Send(configure terminal &