Trying to establish an ssh connection programmatically with a Cisco switch SG250, but the session keeps timing out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 08:55 AM
Hi,
Not sure if it's the right place to ask, but I'm trying to establish an SSH connection programmatically and my session keep timing out.
I want to create a program to wrap the CLI commands of the Cisco switch (SG250-26) to make it easier to use for our users.
In the Cisco switch, I checked the SSH Service checkbox to enable the ssh service.
I am able to establish an ssh connection by using the command line "ssh [ip address]" but I can't wrap the CLI commands this way.
When I try to connect with an SSH client using the hostname, username and password (tried 3 differents library already), the ssh session keeps timing out.
Is there something I need to activate in the Cisco parameters to make this work out?
Any suggestion would be great.
Thanks,
Ktmachinex
- Labels:
-
Branch Router
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 05:09 PM
Personally i do not belive these switches has any API programmability
what kind of test you using, post some example to understand, before we go further are you able to SSH in to device ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2020 05:57 AM
Requirements :
- Visual Studio 2019
- https://github.com/sshnet/SSH.NET
Steps :
- I connect to the cisco ip address 192.168.1.254 2. I go to the Security - TCP/UDP Services 3. I enable the SSH Service 4. I apply and save the change.
- In visual Studio, I try to execute this code :
string host = "192.168.1.254"; int port = 22; string username = "cisco"; string password = "cisco"; try { using (var client = new SshClient(host, port, username, password)) { // Throws an exception on the following line client.Connect(); if (client.IsConnected) { //Do something } } } catch (Exception ex) { //Session operation has timed out Debug.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace.ToString()); }
Each time I try to execute the Connect method, the session keep timing out.
When I try to use the same code to connect to a Linux server instead, it succeed.
Any suggestions?
I can send the "ssh [ip address]" command just fine, but I can't achieve my goal this way which is to wrap the cisco CLI commands into an "easier" to use program.
