简体   繁体   中英

Cannot execute command with SSH.NET on Cisco WLC

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在此处输入图片说明

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.

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM