VB.NET 2012
Win7/64
Project: Interact on command line with Cisco router
How using: Compiled (no modifications) Renci.SshNet to DLL
Firstly, even without me getting this working 100%, it is already the obvious choice for my use.
[My] Problem: I can't figure out a reliable way to send & receive data as if I'm logged in via SSH to a Cisco router.
My issue: I'm finding precious few examples (I write in C# & VB) of doing this, so I've been at it for many hours trying this function and that... I'm not sure I'm doing this correctly at all. Somehow, there is an extra carriage return passed into my SSH session, and although (as you can see) eventually it logs on with enable, unless I can figure out how to send commands and receive full output in return (without extra CRs), I can't write a solid Function() to do it all the time.
The following code, and output, describe the strangeness I'm seeing better than words:
[WARNING: THIS IS UGLY TEST CODE!]
Thanks again for the efforts of the developers and user community. Maybe I can help somehow...
TIA!
pat
:)
Win7/64
Project: Interact on command line with Cisco router
How using: Compiled (no modifications) Renci.SshNet to DLL
Firstly, even without me getting this working 100%, it is already the obvious choice for my use.
[My] Problem: I can't figure out a reliable way to send & receive data as if I'm logged in via SSH to a Cisco router.
My issue: I'm finding precious few examples (I write in C# & VB) of doing this, so I've been at it for many hours trying this function and that... I'm not sure I'm doing this correctly at all. Somehow, there is an extra carriage return passed into my SSH session, and although (as you can see) eventually it logs on with enable, unless I can figure out how to send commands and receive full output in return (without extra CRs), I can't write a solid Function() to do it all the time.
The following code, and output, describe the strangeness I'm seeing better than words:
[WARNING: THIS IS UGLY TEST CODE!]
Private Sub RunTest()
Dim r As String = ""
Try
client.Connect()
' created via: Me.client = New Renci.SshNet.SshClient(config.Host, config.User, config.Pass)
If client.IsConnected Then
Debug.WriteLine("connected? " & client.IsConnected)
ss = GetShellStream(client)
End If
r = ss.Expect(New Regex(">\s*"), System.TimeSpan.FromSeconds(3))
Debug.WriteLine("r1: [" & r & "]")
'========================================
ss.WriteLine("enable")
r = ss.Expect(New Regex("Password: "), System.TimeSpan.FromSeconds(3))
Debug.WriteLine("r2: [" & r & "]")
'========================================
ss.WriteLine("theEnablePassword")
r = ss.Expect(New Regex("#"), System.TimeSpan.FromSeconds(3))
Debug.WriteLine("r3: [" & r & "]")
'========================================
client.Disconnect()
Catch ex As Exception
Debug.WriteLine("exception: " & ex.ToString())
End Try
Debug.WriteLine("Bye!")
Environment.Exit(0)
End Sub
The output is where the issue makes itself apparent:connected? True
r1: [Type help or '?' for a list of available commands.
COL-FRMGT-A> ]
r2: [enable
Password: ]
r3: [
Invalid password <<<<<<<<<<<<< Where did this CR/LF come from?
Password: *****************
COL-FRMGT-A# ]
Bye!
GetShellStream takes the SshClient, and resturns SshStream:Private Function GetShellStream(C As Renci.SshNet.SshClient) As Renci.SshNet.ShellStream
Dim ss As Renci.SshNet.ShellStream = Nothing
Try
ss = C.CreateShellStream("xterm", 80, 24, 800, 600, 1024)
Catch ex As Exception
LogIt(TraceEventType.Critical, "GetShellStream() cannot create new ShellStream: " & ex.ToString())
End Try
Return ss
End Function
Are there any examples of how to do this? There is no shortage of subs & functions, but precious few examples of the proper way to interact with the command line like this. Or at least Google can't find them!Thanks again for the efforts of the developers and user community. Maybe I can help somehow...
TIA!
pat
:)