(1)新建文本文件(注意保存路径,本次测试路径为D:\backup\list.txt):


  x.x.x.x username password enable_password   (#注:如果没有enable密码可以不写;每项用空格分割)


(2)新建文本文件H3C.txt(路径D:\backup\H3C.txt),内容如下:


# $language = "VBScript"

# $interface = "1.0"

'本脚本示范:从一个文件里面自动读取设备IP地址,密码等,自动将设备配置备份

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)        

     crt.Screen.Synchronous = True

     DO While file1.AtEndOfStream <> True

        '读出每行

        line = file1.ReadLine

        '分离每行的参数 IP地址 密码 En密码

        params = Split (line)

       crt.session.LogFileName = "D:\backup\h3c\201611\" & params(0) & ".txt"

       crt.session.Log(true)

        'Telnet到这个设备上

        crt.Session.Connect "/TELNET " & params(0)


        crt.Screen.WaitForString "Username:" 

        crt.Screen.Send params(1) & Chr(13)

        

        '输入telnet密码

        crt.Screen.WaitForString "Password:"

        crt.Screen.Send params(2) & Chr(13)

        '进特权模式

        crt.Screen.Send "sup" & Chr(13)

        crt.Screen.WaitForString "Password:"

        crt.Screen.Send params(3) & Chr(13)

        crt.Screen.waitForString ">"

         '备份目前runing-config配置

        str1 = "disp cur "

        crt.Screen.Send str1 & Chr(13)

        crt.Screen.WaitForString " ---- More ----"

        crt.Screen.Send "                "

        'crt.Screen.Send Chr(13)                                                                                                                                                      " & vbcr

        '备份完成后退出

        crt.Screen.waitForString  "return"

        crt.Screen.waitForString ">" 

        '执行disp int br命令 

        crt.Screen.Send "disp int brief" & Chr(13)

        crt.Screen.WaitForString " ---- More ----"

        crt.Screen.Send "                        "

        crt.Screen.waitForString ">"

        crt.screen.send Chr(13)

        crt.Session.Disconnect  

        loop

     crt.Screen.Synchronous = False           

End Sub


(3)修改上面文本后缀个是为.vbs,即H3C.vbs;


(4)运行CRT软件,菜单栏-->脚本-->执行-->找到脚本路径D:\backup\H3C.vbs;


(5)查看备份文件保存路径