gpt4 book ai didi

c# - 无法在 Cisco WLC 上使用 SSH.NET 执行命令

转载 作者:行者123 更新时间:2023-12-02 14:27:49 33 4
gpt4 key购买 nike

尝试使用 SSH.NET 连接到 Cisco 无线 Controller 并向其添加 MAC 地址。当我调试我的代码时,我得到一个 trueIsConnected客户端的属性,但是当我登录到 Controller 本身并执行“显示登录 session ”时,我没有看到列出的假定连接。
另外,当我到达 var result = client.RunCommand(comman.ToString()).Result;代码只是挂起,根本没有响应。已经离开了几分钟并且没有超时或返回任何类型的错误。
执行以上行时的 PuTTY session 图片 enter image description here
我们使用什么“登录身份”并不重要。

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

运行时 plink user@host config macfilter add 00:17:ab:ea:d4:aa 5 0 Testing1234 ,我得到:

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

最佳答案

您的服务器似乎不支持 SSH "exec" channel 。所以你不能使用CreateCommand/RunCommand .
您必须使用“shell” channel (SshClient.CreateShellSshClient.CreateShellStream)。通常不建议将这用于命令自动化。使用 SSH.NET 更是如此,它甚至不允许您关闭“shell” channel 的伪终端。这带来了许多令人讨厌的副作用,尤其是在 Linux 上使用“智能”shell。但是对于像您这样的设备,它可能是可以忍受的,并且无论如何都是唯一的解决方案。

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

关于c# - 无法在 Cisco WLC 上使用 SSH.NET 执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60288800/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com