1

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

It does not matter what we use for "login as".

public WebAPIEndPoint Put(WebAPIEndPoint console)
{
    var auth = new PasswordAuthenticationMethod("UserName", "Password");
    var connectionInfo = new ConnectionInfo(hostIP, 22, "UserName", auth);

    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;
    }
}

When running plink user@host config macfilter add 00:17:ab:ea:d4:aa 5 0 Testing1234, I get:

FATAL ERROR: Server refused to start a shell/command.

0

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.