2

I have some large project that connect to many devices over SSH.NET

Now I have to add support for new modem witch is digi 6030dx.

I added it and I am able to connect with no issues

But when I send some/any command like show config the output is:

[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

Does anyone known what are this strange signs / why my command is splited by this and newlines? It is first device that have this issue and the app support over 200 other with no issues.

I guess some coding issue or something ? putty does not show this signs so probably 'understand' them somehow?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
d00lar
  • 802
  • 7
  • 25

2 Answers2

3

Those are ANSI escape codes.

In general, with SSH, you get these only if your client (library) declares support for terminal emulation.

SSH.NET library does that always, when you use the "shell" channel (SshClient.CreateShell or SshClient.CreateShellStream).

In general (were you connecting to well behaving SSH server), to avoid getting the codes:

  • Use "exec" channel (use SshClient.RunCommand). SSH.NET does not use terminal emulation on "exec" channel. Though SSH servers on "devices" (contrary to full servers) usually do not implement the "exec" channel. See also What is the difference between exec_command and send with invoke_shell() on Paramiko?

  • Modify SSH.NET code not to request terminal emulation for the "shell" channel. – Remove SendPseudoTerminalRequest request from Shell.Start implementation.


Though as you are connecting to some "device" and telneting further to another device and the codes probably come from the far device, the question is whether this will in fact have any effect on that device at all. Possibly you won't be able to avoid getting the codes. Lack of terminal emulation on the first SSH connection possibly won't have any effect on the second telnet connection.

In the end, you may have to deal with the codes.
See also How to strip ANSI escape codes from AIX topas command result in C#.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

i did for now

this.answer = Regex.Replace(this.answer, @"\r\[\d{0,3}C\[0K", "", RegexOptions.IgnoreCase);

will see if have any negative impact but looks perfect for now :D

d00lar
  • 802
  • 7
  • 25