# $language = "VBScript"
# $interface = "1.0"
Sub Main
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso,file1,line,str1,str2,params
Set fso = CreateObject("Scripting.FileSystemObject")
'设备列表和密码文件路径,运行前需要确认路径!
Set file = fso.OpenTextFile("D:\SW_Scripts\list.txt",Forreading, False)
crt.Screen.Synchronous = True
DO While file.AtEndOfStream <> True
line = file.ReadLine
params = Split (line)
'输出log文件路径,运行前需要确认log文件夹存在!
crt.session.LogFileName = "D:\SW_Scripts\log\" & params(0) & " @"& Year(Now) &"-"& Month(Now) &"-"& Day(Now) &".txt"
crt.session.Log(true)
'登录
crt.Session.Connect "/TELNET " & params(0)
crt.Screen.WaitForString "Username:"
crt.Screen.Send params(1) & vbcr
crt.Screen.WaitForString "Password:"
crt.Screen.Send params(2) & vbcr
crt.Screen.waitForString ">"
str0 = "enable"
crt.Screen.Send str0 & vbcr
crt.Screen.WaitForString "Password:"
crt.Screen.Send params(3) & vbcr
crt.Screen.waitForString "#"
'备份目前startup配置到tftp服务器
str1 = "copy startup-config tftp://192.168.1.111"
str2 = params(0) & "-config" & "@" & Year(Now) &"-"& Month(Now) &"-"& Day(Now) & ".cfg"
crt.Screen.Send str1 & vbcr
crt.Screen.WaitForString "]?"
crt.Screen.Send vbcr
crt.Screen.WaitForString "]?"
crt.Screen.Send str2 & vbcr
crt.Screen.WaitForString "#"
'登出
crt.Session.Disconnect
loop
crt.Screen.Synchronous = False
End Sub