vbscript – auto login via SSH connection to Cisco device without key auth

Due to the fact that Cisco is not capable to use SSH key authentication below IOS 15. I wrote this script to access any kind of  ssh capable device in a secure way.

To use this script there are a few steps to be done before:

First install the Putty client, or put the putty.exe in a specific folder of you choice. than get to the “System Properties -> Advanced -> Environment Variables” and modify the Path variable and add the path to the putty.exe.

Path Variable

In my case the path variable looks like:

C:\Program Files\Parallels\Parallels Tools\Applications;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\Program Files\PuTTY

I had to add just add it might alter in your case:

;C:\Program Files\PuTTY

If the putty windows opens if you only type “putty” in the cmd than everything is fine here.

Second create the profile for your Cisco device. You can use the log file option to generate a log file for each time. In my case I named it “testme”

Putty Profile

No the script:

Option Explicit
On Error Resume Next
Dim WshShell
Dim PUTTYPROFILE 
PUTTYPROFILE = "testme"
set WshShell=CreateObject("WScript.Shell")
WshShell.run "putty.exe -load " & chr(34) & "testme" & chr(34)
WScript.Sleep 4000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
'WshShell.SendKeys ("Y")
WScript.Sleep 4000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys "admin"
WScript.Sleep 2000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 2000
WshShell.SendKeys "cisco"
WScript.Sleep 2000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1500
WshShell.SendKeys ("term length 0")
WScript.Sleep 1500
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1500
WshShell.SendKeys "sh crypto session"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 3000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")

WScript.Quit

 

 

2 comments for “vbscript – auto login via SSH connection to Cisco device without key auth

  1. Chuan
    October 5, 2016 at 23:30

    works perfect thanks

  2. Renan
    February 5, 2017 at 03:05

    I can not export all the lines to the text file. When the file reaches the size of 16Kb, the plink stops recording.

    My Command:

    plink -l USER -pw PASSWORD HOST log.txt

    Today it is exporting around 280 lines, but I have a total of 750.

Leave a Reply

Your email address will not be published. Required fields are marked *