2017-12-07 14 views
0

サーバー(Windows 10 IOTデバイス)にtelnet接続すると、 "open 127.0.0.1 1023"と表示され、ユーザー名を尋ねて接続します。デバイス上で私はユーザー名を持っていないので、私は戻り値を打つことによって接続することができ、パスワードを求めずに私をコマンドプロンプトにまっすぐにつける。クライアント、私は返信で返信するユーザー名を求められます。その後、返信で返信するパスワードを求められ、無効なユーザー名またはパスワードが返され、私の接続が切断されます。TCPClientでのTelnet実装、ユーザー名/パスワードのエラー

これはなぜですか?ユーザー名を追加する必要がありますか、またはTelnetとは異なるTCPClientですか?

おかげ

コード:

  var tcpClient = new TcpClient("127.0.0.1", 1023); 
     var ns = tcpClient.GetStream(); 
     Byte[] output = new Byte[1024]; 
     String response = String.Empty; 
     Byte[] cmd = System.Text.Encoding.ASCII.GetBytes("\n"); 
     ns.Write(cmd, 0, cmd.Length); 
     Thread.Sleep(100); 
     Int32 bytes = ns.Read(output, 0, output.Length); 
     response = System.Text.Encoding.ASCII.GetString(output, 0, bytes); 
     Console.Write(response); 
     Regex objToMatch = new Regex("User name"); 
     if (objToMatch.IsMatch(response)) 
     { 
      cmd = System.Text.Encoding.ASCII.GetBytes("" + "\r"); 
      ns.Write(cmd, 0, cmd.Length); 
     } 

     Thread.Sleep(100); 
     bytes = ns.Read(output, 0, output.Length); 
     response = System.Text.Encoding.ASCII.GetString(output, 0, bytes); 
     Console.Write(response); 
     objToMatch = new Regex("Password"); 
     if (objToMatch.IsMatch(response)) //Both Regex match 
     { 
      cmd = System.Text.Encoding.ASCII.GetBytes("" + "\r"); 
      ns.Write(cmd, 0, cmd.Length); 
     } 
     Thread.Sleep(100); 

     bytes = ns.Read(output, 0, output.Length); 
     response = System.Text.Encoding.ASCII.GetString(output, 0, bytes); 
     Console.Write(response); //Invalid Username/Password response 
     cmd = System.Text.Encoding.ASCII.GetBytes("\r"); 
     ns.Write(cmd, 0, cmd.Length); //Cannot send because connection is closed 
     tcpClient.Close(); 
+0

疑問があれば、wiresharkまたは類似のツールをインストールし、あなたがtelnetで接続するとき。それはあなたが間違っていることについての手がかりを与えるでしょう。 – Evk

+0

「サーバーにtelnet接続すると...」どうやってこれを行うのですか? –

答えて

0

私はそれは、デバイスの問題ではなく、C#またはTelnetの問題と判断しました。私はデバイス上で私のコマンドを実行する別の方法を見つけたので、私はこの質問を閉じることができます、私はかなり誰もこの問題を抱えていないことを確かめてください

関連する問題