设备巡检脚本

设备巡检脚本

VB设备巡检脚本配合CRT使用。
准备资料“设备信息表”,内容格式“127.0.0.1 user password 设备描述”,名字随意,会让你去选择信息存放位置,格式应该还算规整,需要的带走,巡检内容可自己修改,此处以抓取设备配置为例,不能通信的设备及用户名/密码错误的存放至“D:\ip.txt”,log保存路径“D:\devicebackup\”。
#$language = "VBScript"
#$interface = "1.0"
crt.Screen.Synchronous = True
Function Main
    On Error Resume Next
    Const ForReading = 1,ForWriting = 2,ForAppending = 8
	Dim fso,tempFolder,tempName,path,BrowseForFile,file1,line,params,wordkey,f
	Set fso = CreateObject("Scripting.FileSystemObject")
    Set tempFolder = fso.GetSpecialFolder(2)
    tempName = fso.GetTempName() & ".hta"
    path = "HKCU\Volatile Environment\MsgResp"
    With CreateObject("WScript.Shell")        
        With tempFolder.CreateTextFile(tempName)
            .Write "<input type=file name=f>" & _
            "<script>f.click();(new ActiveXObject('WScript.Shell'))" & _
            ".RegWrite('HKCU\\Volatile Environment\\MsgResp', f.value);" & _
            "close();</script>"
            .Close
        End With
        .Run tempFolder & "\" & tempName, 1, True
        BrowseForFile = .RegRead(path)
        .RegDelete path
        fso.DeleteFile tempFolder & "\" & tempName
	End With
	'获取选择文件的路径
    Set file1=fso.OpenTextFile(BrowseForFile,ForReading,False)
    '文件格式:ip 用户名 密码 
    While file1.AtEndOfStream <> True
        line = file1.ReadLine
        params = Split (line)
		 '逐行读取该文件
        crt.Session.Connect "/telnet" & " " & params(0)
		If Err.Number<>0 Then
        '等效 telnet ip地址 23
            set f = fso.OpenTextFile("D:\ip.txt", 8, true)
            f.WriteLine(params(0)+" 设备连接失败 "+params(3))
            f.Close()
		    '不能通信就将管理地址保存,以便查看	
            else			
            crt.Session.LogFileName = "D:\devicebackup\"+params(3)+"\"+ params(0) + chr(32)+Replace(Replace(Replace(date, ":", ""), "/", ""), " ", "") + "_log.txt"
		     '设置Log保存路径
            call crt.Session.Log(false)
            call crt.Session.Log(true)		
                wordkey = crt.Screen.WaitForStrings ("login:","Username:","Password:",3)  
		         '3秒内根据登录提示来选择 
                Select case wordkey
                    case 1
                    crt.Screen.Send params(1) & chr(13)
                    crt.Screen.WaitForString "Password:"
                    crt.Screen.Send params(2) & chr(13)
		    		if (crt.Screen.WaitForString ("Error","refused",1)<>0) then
		    		    set f = fso.OpenTextFile("D:\ip.txt", 8, true)
                        f.WriteLine(params(0)+" 用户名密码错误 "+params(3))
                        f.Close()
		    		    else
		    			Do
                        bCursorMoved = crt.Screen.WaitForCursor(1)
                        Loop until bCursorMoved = False
                        crt.Screen.Send "dis cur" & chr(13)
                            do while (crt.Screen.WaitForString("---- More ----",3)= true)
                            crt.Screen.Send " "
                            loop
		    		end if		
                    case 2
                    crt.Screen.Send params(1) & chr(13)
                    crt.Screen.WaitForString "Password:"
                    crt.Screen.Send params(2) & chr(13)
		    		if (crt.Screen.WaitForString ("Error","refused",1)<>0) then
		    		    set f = fso.OpenTextFile("D:\ip.txt", 8, true)
                        f.WriteLine(params(0)+" 用户名密码错误 "+params(3))
                        f.Close()
		    		    else
		    			Do
                        bCursorMoved = crt.Screen.WaitForCursor(1)
                        Loop until bCursorMoved = False
                        crt.Screen.Send "dis cur" & chr(13)
                            do while (crt.Screen.WaitForString("---- More ----",3)= true)
                            crt.Screen.Send " "
                            loop
		    		end if		
                    case 3
                    crt.Screen.Send params(1) & chr(13)
                    crt.Screen.WaitForString "Password:"
                    crt.Screen.Send params(2) & chr(13)
		    		if (crt.Screen.WaitForString ("Error","refused",1)<>0) then
		    		    set f = fso.OpenTextFile("D:\ip.txt", 8, true)
                        f.WriteLine(params(0)+" 用户名密码错误 "+params(3))
                        f.Close()
		    		    else
		    			Do
                        bCursorMoved = crt.Screen.WaitForCursor(1)
                        Loop until bCursorMoved = False
                        crt.Screen.Send "dis cur" & chr(13)
                            do while (crt.Screen.WaitForString("---- More ----",3)= true)
                            crt.Screen.Send " "
                            loop
		    		end if	
                End Select
                call crt.Session.Log(false)
		end if
        crt.Session.Disconnect
    wend
    crt.Screen.Synchronous = False
End Function
创作不易,转发请注明出处。
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值