捕获对变量的 SSH 响应
Capture SSH Response to variable
我目前正在尝试 "talk" 通过 C# 使用 SSH 命令连接到路由器。
我正在使用 SSH.net 模型。
public void connectSSH(string hostName, string username, string password)
{
using (var client = new SshClient(hostName, username, password))
{
client.Connect();
client.RunCommand(CommandList.showEnvironment());
client.Disconnect();
}
}
这是我目前的代码(所有命令都在另一个文件中)。理想情况下,我将能够捕获路由器对命令的响应,而不仅仅是单向传送和执行命令。
如何捕获响应?例如;命令 "show environment" 以因子列表响应
单位温度Descr/IDCurrent/Threshold范围
1 中环 Temperature/1 27C/11~79C
状态码:* 温度超出阈值范围
详细范
SSH.net 中的 SshCommand 包含用于响应的属性 Result 和 Error。
我猜你的 CommandList 只是一个 List ?
在 运行 您的命令之后,您应该能够从 2 个属性中检索结果。
我目前正在尝试 "talk" 通过 C# 使用 SSH 命令连接到路由器。
我正在使用 SSH.net 模型。
public void connectSSH(string hostName, string username, string password)
{
using (var client = new SshClient(hostName, username, password))
{
client.Connect();
client.RunCommand(CommandList.showEnvironment());
client.Disconnect();
}
}
这是我目前的代码(所有命令都在另一个文件中)。理想情况下,我将能够捕获路由器对命令的响应,而不仅仅是单向传送和执行命令。
如何捕获响应?例如;命令 "show environment" 以因子列表响应
单位温度Descr/IDCurrent/Threshold范围
1 中环 Temperature/1 27C/11~79C 状态码:* 温度超出阈值范围 详细范
SSH.net 中的 SshCommand 包含用于响应的属性 Result 和 Error。 我猜你的 CommandList 只是一个 List ? 在 运行 您的命令之后,您应该能够从 2 个属性中检索结果。