This project is read-only.

StreamReader content and non printable characters

Dec 23, 2014 at 3:12 PM
Hello Comminuty,

i have 2 questions.

1) I use SSH.NET for Shell connection to SSH hosts with
public class Connector
        SshClient ssh;
        StreamReader read;
        StreamWriter write;
        ShellStream shell;
        Thread readerThread;

        public Connector(string ip, string user, string password)
            Console.CancelKeyPress += Console_CancelKeyPress;
            ssh = new SshClient(ip, user, password);
            readerThread = new Thread(new ThreadStart(Reader));

        void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
        public void Connector2()
            shell = ssh.CreateShellStream("vt100", 80, 24, 800, 600, 1024);
            read = new StreamReader(shell);
            write = new StreamWriter(shell);
            Console.TreatControlCAsInput = true;

            } while (ssh.IsConnected);

        private void Reader()
            while (true)
                if(!ssh.IsConnected) continue;
                if (read == null)
                string result = read.ReadToEnd();
                if (string.IsNullOrEmpty(result))
But StreamReader not only returns console output, it also returns my input.
For example, i type "ping" and got "ppiinngg 88..88..88..88" in console window. It is not an functionality issue, its more optical issue.

2) Like point 1, its more optical issue. I have sometimes non printable characters form a MikroTik router, but never had non printable characters when using putty oder something else.
♥←[K    ←[m←[32msent=←[m5 ←[m←[32mreceived=←[m5 ←[m←[32mpacket-loss=←[m0% ←[m←[3
2mmin-rtt=←[m3ms ←[m←[32mavg-rtt=←[m3ms ←[m←[32mmax-rtt=←[m3ms
In putty it the same link is
    sent=5 received=5 packet-loss=0% min-rtt=2ms avg-rtt=2ms max-rtt=3ms
Any solutions for this?

Dec 23, 2014 at 4:13 PM
Edited Dec 23, 2014 at 4:14 PM
Solved the first issue by supressing key output on console with
so every output comes from StreamReader.
Dec 23, 2014 at 6:50 PM
Edited Dec 23, 2014 at 6:52 PM

to 1) Yes, thats expected behavior. The SSH server sends back your input, cause it's also output on the shell.

to 2) You have to handle the terminal protocol. SSH.NET just gives you access to the shell stream.
You don't see those chars in putty, cause it handles the terminal protocols. In your case vt100.
Dec 24, 2014 at 9:30 AM
Hello da_rinkes,

thanks for your explanation.
Now i got another question. I have one type of machines where i had no luck to connect via SSH.NET but putty has no problem.
SSH.NET says "Renci.SshNet.SshOperationTimeoutException" when i call the "Connect" method of SshClient.

I checked both, putty and SSH.NET connection via Wireshark and SSH.NET stuck before Key Exchange

32625 1429.943738000 TCP 66 40283→22 [SYN] Seq=0 Win=65535 Len=0 MSS=1460 WS=4 SACK_PERM=1
32626 1429.959065000 TCP 66 22→40283 [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1460 SACK_PERM=1 WS=16
32627 1429.959157000 TCP 54 40283→22 [ACK] Seq=1 Ack=1 Win=137072 Len=0
32629 1429.979514000 SSHv2 70 Server: Protocol (SSH-2.0-SSH.1.0)
32630 1429.989451000 SSHv2 92 Client: Protocol (SSH-2.0-Renci.SshNet.SshClient.0.0.1)
33421 1474.605012000 TCP 66 40300→22 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
33422 1474.618777000 TCP 66 22→40300 [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1460 SACK_PERM=1 WS=16
33423 1474.618874000 TCP 54 40300→22 [ACK] Seq=1 Ack=1 Win=65536 Len=0
33424 1474.628474000 SSHv2 70 Server: Protocol (SSH-2.0-SSH.1.0)
33425 1474.628878000 SSHv2 82 Client: Protocol (SSH-2.0-PuTTY_Release_0.63)
33426 1474.628949000 SSHv2 726 Client: Key Exchange Init
33427 1474.638400000 TCP 60 22→40300 [ACK] Seq=17 Ack=29 Win=5840 Len=0
33428 1474.648490000 TCP 60 22→40300 [ACK] Seq=17 Ack=701 Win=8768 Len=0
33429 1474.649245000 SSHv2 302 Server: Key Exchange Init
33430 1474.697866000 TCP 54 40300→22 [ACK] Seq=701 Ack=265 Win=65280 Len=0
33449 1475.809952000 SSHv2 198 Client: Diffie-Hellman Key Exchange Init
33450 1475.851027000 TCP 60 22→40300 [ACK] Seq=265 Ack=845 Win=10112 Len=0
33496 1477.154579000 SSHv2 694 Server: Diffie-Hellman Key Exchange Reply
33497 1477.173475000 SSHv2 70 Client: New Keys
33498 1477.185717000 SSHv2 70 Server: New Keys
With putty i got that the server uses "diffie-hellman-group1-sha1" as key-exchange algorithm, so i call
            ssh.ConnectionInfo.KeyExchangeAlgorithms.Add("diffie-hellman-group1-sha1", typeof(Renci.SshNet.Security.KeyExchangeDiffieHellmanGroup1Sha1));
The Server says nothing in logfiles and since it is a proprietary router firmware, i have no chance to extend logging or something on the server.
The only settings i can change are
ssh server : enable / disable
ssh authtype : pap / chap
ssh version : sshv1 / sshv2

Actually it is
ssh server : enable
ssh authtype : pap
ssh version : sshv2

Thanks in advance
Dec 26, 2014 at 4:37 PM

The connection problem you reported is caused by two stubborn SSH implementations.
Both SSH.NET and your router are waiting for the SSH_MSG_KEXINIT of the other party before sending the SSH_MSG_KEXINIT messages themselves.
Please submit an issue for SSH.NET.

Jan 5, 2015 at 8:18 AM
Hello Gert,

i submited an issue as you proposed, thanks for your help.