View Single Post
  #32  
Old 02-27-2012, 11:09 AM
stuartX stuartX is offline
Registered User
 
Join Date: Feb 2012
Posts: 33
Yes, the file path is there (attached screenshot). And the router device is up on the network and is accessible via telnet.

Below is the code:

Code:
# $language = "VBScript"
# $interface = "1.0"
Sub Main
    strUsername = "user" 
    strPassword = "password" 
    strPrompt = "#"
    Set fso = CreateObject("Scripting.FileSystemObject")
    strDeviceList = "s:\riggs\Test-router-1.txt"
    Set fil = fso.OpenTextFile(strDeviceList)
    ' Start loop to iterate over all devices defined in file
    While Not fil.AtEndOfStream
        ' Process a line at a time
        vLine = Split(fil.ReadLine, ";")
        strHostname = vLine(0)
        strIP = vLine(1)
        strProtocol = vLine(2)
        ' Generate a connection string
        Select Case strProtocol
            Case "Telnet"
                cnxnString = "/TELNET " & strIP & " 23"
                ' Don't wait for connection to complete before moving on because
                ' we are going to handle authentication after connecting.                
                bWait = False
            Case "SSH2"
                cnxnString = "/SSH2 /L " & strUsername & " /PASSWORD " & strPassword & " " & strIP
                ' Wait for connection to complete before moving on.
                bWait = True
            Case "SSH1"
                cnxnString = "/SSH1 /L " & strUsername & " /PASSWORD " & strPassword & " " & strIP
                ' Wait for connection to complete before moving on.
                bWait = True
            End Select	
        'Handle possible errors when connecting
        crt.Dialog.MessageBox "Connect string:" & vbcrlf & vbtab & cnxcString &_
            vbcrlf & "Should I wait:" & vbcrlf & vbtab & bWait
        On Error Resume Next
            crt.Session.Connect cnxnString, bWait
            strErr = Err.Description
            nError = Err.Number
        On Error Goto 0
        
        ' Enable Synchronous which is necessary for not missing data from remote
        crt.Screen.Synchronous = True
        
        ' Handle Telnet authentication
       If strProtocol = "Telnet" Then
            crt.Screen.Send vbcr
            nIndex = crt.Screen.WaitForStrings("login:", "Password:")
          
              
            ' Handle authentication starting at username
            If nIndex = 1 Then 
                crt.Screen.Send strUsername & vbcr
                crt.Screen.WaitForString "Password:"
                crt.Screen.Send strPassword & vbcr
                
            ' Handle authentication starting at password
            Else
                crt.Screen.Send strPassword & vbcr
            End If
        End If
        ' Confirm that remote is ready
        crt.Screen.WaitForString strPrompt
        ' Start logging to new file
        strLogFile = "C:\Switches\" & strHostname & "-%Y-%M-%D--%h-%m-%s.%t.txt"
        crt.Session.LogFileName = strLogFile
        crt.Session.Log True
        ' Turn off paging
        crt.Screen.Send "term length 0" & vbcr	
        crt.Screen.WaitForString strPrompt
        ' Send commands
        crt.Screen.Send "show proc cpu | inc CPU" & vbcr
        crt.Screen.WaitForString strPrompt
        crt.Screen.Send "show version" & vbcr 
        crt.Screen.WaitForString strPrompt
        ' Stop logging
        crt.Session.Log False
        ' Disconnect from device
        If crt.Session.Connected Then
            crt.Session.Disconnect
        End If
    Wend
    ' Close device file
    fil.Close 
End Sub
Reply With Quote