使用securecrt VBS自动备份网络设备配置
[code=vbscript]
Sub Main
rem 打开保存设备管理地址以及密码的文件
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso,file1,line,str1,params
Dim SwitchKey
Dim tftpip
Dim savedpath
dim tftpcom
Set fso = CreateObject("Scripting.FileSystemObject")
if checkip() <> true then
checkip()
end if
if checkpath() <> true then
checkpath()
end if
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
'分离每行的参数 IP地址 密码 密码
params = Split (line)
tftpcom = "tftp"&chr(32)+tftpip&chr(32)+"put starg.cfg"&chr(32)¶ms(4)+".cfg"
msgbox (tftpcom)
crt.session.LogFileName = savedpath & params(0) & ".txt"
crt.session.Log(true)
'Telnet到这个设备上
crt.Session.Connect "/TELNET " & params(0)
SwitchKey = crt.Screen.WaitForStrings("H3C","cisco","dptech","huawei",5,true) rem 根据telnet设备第一步判断设备品牌,最后数字为等待时间
Select case SwitchKey
case 1
rem 输入用户名
crt.screen.waitForString "Username:"
crt.Screen.Send params(1) & Chr(13)
rem 输入密码
crt.screen.waitForString "Password:"
crt.Screen.Send params(2) & Chr(13)
crt.screen.send tftpcom & chr(13)
case 2
cisco ()
case 3
dptech ()
case 4
huawei ()
case else
MsgBox "未知设备"
End Select
loop
crt.Screen.Synchronous = False
End Sub
function checkip
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)
End If
checkip = (true)
end Function
function checkpath
savedpath = crt.Dialog.Prompt("例如c:\users\", "请输入保存路径", "", false)
If (Trim(savedpath) = "") Or (savedpath = IDABORT) Then
result = crt.Dialog.MessageBox("您没有输入保存路径或输入的路径有错误", "提示信息",ICON_INFO)
End If
rem savedpath = crt.Dialog.FileopenDialog ("请选择一个文件", "Open", "", "*.*") 预留文件保存选择框功能
rem tftpip = crt.Dialog.Prompt("例如192.168.1.1","请输入tftp服务器地址","",false)
rem crt.Dialog.MessageBox(""您输入的IP地址为:"& tftpip","请确认IP地址",1)
checkpath = (true)
end Function
[/code]
在给变量tftpcom赋值的时候,引入了tftpip的变量,但是该句引入的tftpipb变量无效,请问问题出在哪里