使用securecrt VBS自动备份网络设备配置

squalliskm 2017-05-31 08:54:31
[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变量无效,请问问题出在哪里
...全文
1122 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hookee 2017-06-01
  • 打赏
  • 举报
回复
tftpip 是定义在 Main里的,赋值是在 其他函数里。 把tftpip定义成全局变量试试。
squalliskm 2017-06-01
  • 打赏
  • 举报
回复
非常感谢,已经解决,没注意到变量不是全局的

4,008

社区成员

发帖
与我相关
我的任务
社区描述
它是一种微软环境下的轻量级的解释型语言,它使用COM组件、WMI、WSH、ADSI访问系统中的元素,对系统进行管理。
社区管理员
  • vbScript社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧