Home » c# » c# – Can not get SSH.net to connect to Cisco WLC-Exceptionshub

c# – Can not get SSH.net to connect to Cisco WLC-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

Trying to use SSH.net to connect to the cisco wireless controller and add a mac address to it. When i debug my code i am getting a “true” on the “IsConnected” property of the client but when i log onto the controller itself and do a “Show loginsession” i am not seeing the supposed connection being listed.

Also, when i get to var result = client.RunCommand(comman.ToString()).Result; the code just hangs with no response at all. Have left for several minutes and does not timeout or return any sort of error.

Picture of putty session when executing above line enter image description here

        public WebAPIEndPoint Put(WebAPIEndPoint console)
        {

            var connectionInfo = new ConnectionInfo(hostIP, 22, "UserName", new PasswordAuthenticationMethod("UserName", "Password"));

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();

                var command = client.CreateCommand("config macfilter add 00:17:ab:ea:d4:aa 5 0 Testing1234");

                var result = client.RunCommand(comman.ToString()).Result;

                Console.WriteLine(result);

                client.Disconnect();

                return console;
            }
        }
How to&Answers:

Your server does not seem to support SSH “exec” channel. So you cannot use CreateCommand/RunCommand.

You have to use a “shell” channel (SshClient.CreateShell or SshClient.CreateShellStream). This is normally not recommended for a command automation. Even more so with SSH.NET, which does not even allow your to turn off a pseudo terminal for the “shell” channel. This brings lots of nasty side effects, particularly with “smart” shells on Linux. But with devices likes yours, it might be bearable and the only solution anyway.

ShellStream shellStream = client.CreateShellStream(string.Empty, 0, 0, 0, 0, 0);
shellStream.Write("username\n");
shellStream.Write("password\n");
shellStream.Write("config macfilter add 00:17:ab:ea:d4:aa 5 0 Testing1234\n");