Can't Telnet to Cisco equipment (wodSSH / wodSSH.NET)
Hello everyone,
I'm trying to build a simple script in VB Script that will log in to Telnet-enabled Cisco routers and switches. Here is my script:
---------------
Set wodssh1 = WScript.CreateObject( WeOnlyDo.wodSSHCom.1 )
wodSSH1.Port = 23
wodSSH1.Timeout = 10
wodSSH1.Protocol = 1 'Telnet
wodSSH1.Blocking = 1 'True
wodSSH1.HostName = IP
wodSSH1.Login = USER
wodSSH1.Password = PASS
wodSSH1.connect
wodssh1.execute show ver & vbcrlf, --More--
wscript.echo(wodssh1.receive)
wodssh1.disconnect
-----------------
The problem is, the script hangs at the wodssh1.receive call. When I capture packets, I see that the raw Telnet data (user, pass, and command) is being sent, but nothing ever gets returned to my script to echo. It just waits. Also, when I modify my script to use the PEEK method, nothing ever gets returned.
Help!
Thanks,
Johnny [:sad:]
Re: Can't Telnet to Cisco equipment
Hi Johnny,
Please try something like this:
[code]Set wodssh1 = WScript.CreateObject( WeOnlyDo.wodSSHCom.1 )
wodSSH1.Protocol = 1 'Telnet
wodSSH1.Port = 23 ' first Protocol then Port Property
wodSSH1.Timeout = 10
wodSSH1.Blocking = 1 'True
wodSSH1.HostName = IP
wodSSH1.Login = USER
wodSSH1.Password = PASS
wodSSH1.Connect
wodSSH1.WaitFor ( regex:[$ #>] $ ) 'wait for prompt
wodSSH1.DataReady = 0
Wscript.Echo(wodSSH1.Execute( show ver + vbLf, regex:[$ #>] $ )) 'execute command and receive it in message box
wodSSH1.Disconnect[/code]
Let us know how it goes.
Regards,
Drazen
Re: Can't Telnet to Cisco equipment
Hi Johnny,
Please try something like this:
[code]Set wodssh1 = WScript.CreateObject( WeOnlyDo.wodSSHCom.1 )wodSSH1.Protocol = 1 'Telnet
wodSSH1.Port = 23 ' first Protocol then Port Property
wodSSH1.Timeout = 10
wodSSH1.Blocking = 1 'True
wodSSH1.HostName = IP
wodSSH1.Login = USER
wodSSH1.Password = PASS
wodSSH1.ConnectwodSSH1.WaitFor ( regex:[$ #>] $ ) 'wait for prompt
wodSSH1.DataReady = 0
Wscript.Echo(wodSSH1.Execute( show ver + vbLf, regex:[$ #>] $ )) 'execute command and receive it in message box
wodSSH1.Disconnect[/code]
Let us know how it goes.
Regards,
Drazen
Hello again,
I tried your code and it worked with a little tweaking of the regexes. Thanks. However, I'm encountering the dreaded --More-- Cisco prompt when I run the command. I was wondering how to use the Peek method, since I could write a loop that looks for the --More-- prompt and deal with it accordingly, since I don't know how many times I'll get the --More-- prompt when I run a command. It might be once, or it might be twenty times. I don't have the access priveleges to do the term 0 command.
I've tried Peek ing at the buffer while the script is running, but it never returns any data.
Any ideas?
Thanks,
Johnny.
Re: Cant Telnet to Cisco equipment
Johnny,
I think this should work:
[code]
...
wodSSH1.StripANSI = True
wodSSH1.Connect
Dim a,b,wodSSH1
wodSSH1.WaitFor ( regex:[$ #>] $ )
wodSSH1.DataReady = 0
wodSSH1.Send ls -al | more + vbLf
b = CStr(wodSSH1.WaitFor( --More-- ))
On Error Resume Next
wodSSH1.Timeout = 10
Do
wodSSH1.Send ( + vbLf)
a = CStr(wodSSH1.WaitFor( --More-- ))
If Err.Number <> 0 Then
a =
End If
b = b + a
Loop Until Len(a) = 0
b = b + wodSSH1.Receive 'receive rest
Wscript.Echo(b)
[/code]
Let us know how it goes.
Drazen
Re: Cant Telnet to Cisco equipment
Hello again,
YAHOOOOOOOOOOOOOOOOOOOOOOOOOO! IT WORKED!!!!!!!!!!!!!!!!!!!!
Here's the entire script, which will be of use to many of us who are trying to Telnet to Cisco equipment:
----------------
Set wodssh1 = WScript.CreateObject( WeOnlyDo.wodSSHCom.1 )
wodSSH1.Protocol = 1 'Telnet
wodSSH1.Port = 23 ' first Protocol then Port Property
wodSSH1.Timeout = 10
wodSSH1.Blocking = 1 'True
wodSSH1.HostName = HOST
wodSSH1.Login = USERID
wodSSH1.Password = PASSWORD
wodSSH1.StripANSI = True
wodSSH1.Connect
Dim a,b,wodSSH1
wodSSH1.WaitFor ( regex:[$ #>]$ )
wodSSH1.DataReady = 0
wodSSH1.Send show interface + vbLf ' Cisco command goes here
b = CStr(wodSSH1.WaitFor( --More-- ))
On Error Resume Next
wodSSH1.Timeout = 10
Do
wodSSH1.Send ( )
a = CStr(wodSSH1.WaitFor( --More-- ))
If Err.Number <> 0 Then
a =
End If
b = b + a
Loop Until Len(a) = 0
b = b + wodSSH1.Receive 'receive rest
wodssh1.send exit & vblf
Wscript.Echo( b )
----------------
Thank you again for your speedy assistance!
Johnny
[:cool:][:cool:][:cool:][:cool:][:cool:]