SecureCRT使用VBS脚本自动备份网络设备配置,目前支持部分H3C及dptech
来源:互联网 发布:全球发生交通事故数据 编辑:程序博客网 时间:2024/04/29 19:19
根据网络上的脚本自行捣鼓了下crt自动备份,欢迎各网络管理员试用及提出优化建议。H3C备份方式主要为cfg通过TFTP导出,dptech为屏幕记录,请自行准备独立TFTP工具。
#$language = "VBScript"
#$interface = "1.0"
Dim tftpip
Dim savedpath
Dim fso,file1,line,str1,params
Dim judgebrand '判断设备类型
dim configfiletype '判断配置文件类型
dim h3cconfig,h3cstartup' tftp备份文件时参数
dim showrun
dim tftppath
showrun = "show running-config"
tftpname()
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec(tftppath) rem 启动自定义TFTP服务器
checkip()
checkpath()
Sub Main
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set file1 = fso.OpenTextFile("D:\Users\administrator\Desktop\test backup vbs\list.txt",Forreading, False)
rem list文件格式("IP" "用户名" "密码" "特权密码" "设备名称")
crt.Screen.Synchronous = True
DO While file1.AtEndOfStream <> True
line = file1.ReadLine '读出每行
params = Split (line) '分离每行的参数 IP地址 密码 密码
'crt.session.LogFileName = savedpath & params(0) & ".txt" 屏幕文字抓取保存路径
'crt.session.Log(true) 屏幕文字抓取开关
crt.Session.Connect "/TELNET " & params(0) 'Telnet到这个设备上
judgebrand = crt.Screen.WaitForStrings("H3C","cisco","dptech","Huawei-3Com",5,true) rem 判断设备品牌,延迟5秒,不区分大小写
h3cconfig = "tftp"&chr(32)+tftpip&chr(32)+"put config.cfg"&chr(32)¶ms(4)+"("¶ms(0)+")"+".cfg"
h3cstartup = "tftp"&chr(32)+tftpip&chr(32)+"put startup.cfg"&chr(32)¶ms(4)+"("¶ms(0)+")"+".cfg"
Select case judgebrand
case 1 'h3c设备备份
h3cbackup()
case 2 'cisco 设备备份
MsgBox "未知设备"
case 3 'dptech设备备份
crt.screen.waitForString "Username:"
crt.Screen.Send params(1) & Chr(13)
crt.screen.waitForString "Password:"
crt.Screen.Send params(2) & Chr(13)
crt.session.LogFileName = savedpath & params(0) & ".txt" '屏幕文字抓取保存路径
crt.session.Log(true) '屏幕文字抓取开关
if crt.screen.WaitForString(">",3,true) then
crt.Screen.Send showrun & Chr(13)
srw()
end if
case 4
h3cbackup()
case else
msgbox "出现未知品牌设备,请从list列表中手动排除IP为" +params(0)+"及同批次设备"
exit sub
End Select
loop
crt.Screen.Synchronous = False
End Sub
function checkip '检查TFTP服务器IP地址
tftpip = crt.Dialog.Prompt("例如192.168.1.1", "请输入TFTP服务器IP地址", "", false)
If (Trim(tftpip) = "") Or (tftpip = IDABORT) Then
result = crt.Dialog.MessageBox("您没有输入tftp服务器的IP地址或输入的IP地址有错误", "提示信息",ICON_INFO)
checkip()
End If
end Function
function checkpath '通过屏幕抓取配置文件方式保存路径
savedpath = crt.Dialog.Prompt("例如d:\users\", "请输入保存路径", "", false)
If (Trim(savedpath) = "") Or (savedpath = IDABORT) Then
result = crt.Dialog.MessageBox("您没有输入保存路径或输入的路径有错误", "提示信息",ICON_INFO)
checkpath()
End If
end Function
function tftpname '外置TFTP程序
tftppath = crt.Dialog.Prompt("例如d:\users\tftp.exe", "请输tftp服务器绝对路径", "", false)
If (Trim(tftppath) = "") Or (tftppath = IDABORT) Then
result = crt.Dialog.MessageBox("您输入tftp路径有错误", "提示信息",ICON_INFO)
tftpname()
End If
end Function
function srw()
showrunwait = crt.screen.waitForStrings("--more--",">",3,true)
select case showrunwait
case 1
crt.Screen.Send Chr(32)
srw()
case else
crt.Session.Disconnect
end select
end function
function h3cbackup
crt.screen.waitForString "Username:"
crt.Screen.Send params(1) & Chr(13)
crt.screen.waitForString "Password:"
crt.Screen.Send params(2) & Chr(13)
if crt.screen.WaitForString(">",3,true) then
crt.screen.send "dir" & chr(13)& chr(13)
end if
configfiletype =crt.screen.waitForStrings("config.cfg","startup.cfg",3,true)
select case configfiletype
case 1
crt.screen.send h3cconfig & chr(13)
case else
crt.screen.send h3cstartup & chr(13)
end select
crt.screen.waitForString("successfully")
crt.screen.send Chr(13)
crt.Session.Disconnect
end function
- SecureCRT使用VBS脚本自动备份网络设备配置,目前支持部分H3C及dptech
- VBS教程及secureCRT脚本
- 自动备份华为交换机配置的SecureCRT的脚本
- 局域网文件自动备份 VBS 脚本
- 通过脚本自动登录设备进行设备配置备份CRT vbs脚本
- securecrt的vbs脚本
- SecureCRT vbs脚本小记
- secureCRT脚本----vbs语法
- secureCRT自动登录配置脚本
- 核心网络设备配置及参数如何备份
- 使用SecureCRT录制自动脚本
- 两段secureCRT VBS脚本
- [VBS]使用脚本自动发送邮件
- Iiscnfg.vbs IIS 配置脚本的使用
- 自动朗读VBS脚本
- 使用Adsutil.vbs脚本获取IIS配置信息及账号密码
- 使用Adsutil.vbs脚本获取IIS配置信息及账号密码
- 使用Adsutil.vbs脚本获取IIS配置信息及账号密码
- 凯撒密码
- List-ArrayList
- Java 多线程
- 面向对象-继承中的面试题:代码块
- 自制Java 虚拟机(一)解析class文件
- SecureCRT使用VBS脚本自动备份网络设备配置,目前支持部分H3C及dptech
- 6月1日,每日20行。
- 《UNIX网络编程 卷1》 笔记: 互斥锁与条件变量
- Css之双列自适应布局
- Spring Cloud Bus 教程
- 关卡流
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛—K
- maven仓库更新太慢
- 多线程知识巩固(七)dispatch_barrier_async