我有一些大型项目通过 SSH.NET 连接到许多设备
现在我必须添加对新调制解调器 digi 6030dx 的支持。
我添加了它,并且可以毫无问题地连接
但是当我发送一些/任何命令(例如 show config
)时,输出是:
[16C[0K
[16C[0Ks
[17C[0Kh
[18C[0Ko
[19C[0Kw
[20C[0K
[20C[0Kc
[21C[0Ko
[22C[0Kn
[23C[0Kf
[24C[0Ki
[25C[0Kg
Commands
-------------------------------------------------------------------------------
config View and modify the configuration
exit Exit the CLI
analyzer Analyzer commands.
cli-legacy Enter the legacy Admin CLI.
cp Copy a file or directory.
help Show CLI editing and navigation commands.
ls List a directory.
mkdir Create a directory.
modem Modem commands.
more View a file.
mv Move a file or directory.
ping Ping a host.
reboot Reboot the system.
rm Remove a file or directory.
scp Copy a file or directory over SSH.
show Show instance statistics.
system System commands.
traceroute Print the route packets trace to network host.
update Update firmware.
dra.wk.0001> ashowconfigdra.wk.0001> ashowconfig
[16C[0K
有谁知道这个奇怪的标志是什么/为什么我的命令被这个和换行符分开? 这是第一台存在此问题的设备,该应用程序支持 200 多种其他设备,没有任何问题。
我猜是编码问题还是其他什么问题? putty 没有显示出这些迹象,所以可能以某种方式“理解”它们?
最佳答案
这些是 ANSI escape codes .
一般来说,使用 SSH,只有当您的客户端(库)声明支持 terminal emulation 时,您才能获得这些信息。 .
当您使用“shell” channel (SshClient.CreateShell
或 SshClient.CreateShellStream
)时,SSH.NET 库始终会执行此操作。
一般来说(您是否连接到运行良好的 SSH 服务器),以避免获取代码:
使用“exec” channel (使用
SshClient.RunCommand
)。 SSH.NET 不在“exec” channel 上使用终端仿真。尽管“设备”上的 SSH 服务器(与完整服务器相反)通常不实现“exec” channel 。另请参阅What is the difference between exec_command and send with invoke_shell() on Paramiko?修改 SSH.NET 代码以不请求“shell” channel 的终端仿真。 – 从
Shell.Start
实现中删除SendPseudoTerminalRequest
请求。
虽然您正在连接到某个“设备”并进一步远程登录到另一个设备,并且代码可能来自远端设备,但问题是这实际上是否会对该设备产生任何影响。您可能无法避免获得代码。第一个 SSH 连接缺乏终端模拟可能不会对第二个 telnet 连接产生任何影响。
最后,您可能必须处理这些代码。
另请参阅How to strip ANSI escape codes from AIX topas command result in C# .
关于c# - 在 digi 6030dx 调制解调器上使用 SSH.NET 执行命令 - 以左方括号开头的字符序列是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60318258/