#$language = "VBScript"
#$interface = "1.0"
' Script Autorellenar el usuario/contraseña.
' Version = 1.5
Option Explicit
crt.Screen.Synchronous = True
' Declare standard global variables
Dim strUName, strUPwd, objFSO, objFile
Const ForReading = 1
Const Pathlocation = "C:\Blog\Scripts"
Const CiscoIosPrompt = "Username: "
Const CiscoIosPrompt2 = "username: "
Const DellChassisPrompt = "User Name:"
Sub Main
' Create file object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Call to Procedure to see if credentials are known
Call checkCred(strUName, strUPwd, objFSO)
' return terminal session screen back to nondisruptive
crt.Screen.Synchronous = False
' Clear out file object
Set objFSO = Nothing
End Sub
Sub checkCred(strUName, strUPwd, objFSO)
' Declare procecure variables
Dim intKnown, intFileExist
intKnown = 0
intFileExist = 0
' Check if data file exist
If objFSO.FileExists(Pathlocation) Then intFileExist = 1
' Conditional check if credentials are known
If strUName = "" Then intKnown = intKnown + 1
If strUPwd = "" Then intKnown = intKnown + 1
If (intKnown > 0) And (intFileExist = 1) Then
Call readInInfo (strUName, strUPwd, objFSO, objFile)
Else
Call userCred(strUName, strUPwd)
End If
' Credentials should be known now call userLogin
Call userLogin(strUName, strUPwd)
End Sub
Sub readInInfo (strUName, strUPwd, objFSO, objFile)
' Declare procecure variables
Dim strTxtData, arrTxtData
' Open text file for reading
Set objFile = objFSO.OpenTextFile(Pathlocation, ForReading)
' Read in data from text file
strTxtData = objFile.ReadAll
' Close out text file
objFile.Close
' Break out long string using split on delimiter of carriage return
arrTxtData = Split(strTxtData, vbCrLf)
' Place data in String from Array elements
strUName = arrTxtData(0)
strUPwd = arrTxtData(1)
End Sub
Sub userCred(strUName, strUPwd)
' Dialog prompts to collect the access credentials used in this script
strUName = crt.Dialog.Prompt("Enter Username:", "Username - TACACS or LOCAL", "", False )
strUPwd = crt.Dialog.Prompt("Enter Password:", "Password - TACACS or LOCAL", "", True )
End Sub
Sub userLogin(strUName, strUPwd)
' Declare procecure variables
Dim intLogin
' Login using provided credentials, check for different prompts
' WaitForStrings returns index of string as result,
' used to check prompt response selections or 0 = timeout
'
intLogin = crt.Screen.WaitForStrings(CiscoIosPrompt, DellChassisPrompt, CiscoIosPrompt2, 3)
If intLogin > 3 Then
MsgBox "No se puede detectar el tipo de prompt!"
Exit Sub
ElseIf intLogin = 0 Then
MsgBox "Timeout!, prompt no detectado :-)"
Exit Sub
Else
'crt.Sleep 3000
crt.Screen.WaitForString "Username: ", 1
crt.Screen.Send strUName & chr(13)
crt.Sleep 2000
crt.Screen.WaitForString "assword: ", 1
crt.Screen.Send strUPwd & chr(13)
crt.Sleep 2000
crt.Screen.WaitForString "username: ", 1
crt.Screen.Send strUPwd & chr(13)
End If
' Use condition to see if enable access is available, otherwise enable
If (crt.Screen.WaitForString("#", 1)) Or (crt.Screen.WaitForString("(enable)", 1)) Or (crt.Screen.WaitForString("*", 1)) Then
crt.Window.Activate()
Else
'crt.Sleep 3000
crt.Screen.WaitForString "Username: "
crt.Screen.Send strUName & chr(13)
crt.Sleep 2000
crt.Screen.WaitForString "assword: ", 1
crt.Screen.Send strUPwd & chr(13)
crt.Screen.WaitForString "#", 1
End If
End Sub
|