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();
疑問があれば、wiresharkまたは類似のツールをインストールし、あなたがtelnetで接続するとき。それはあなたが間違っていることについての手がかりを与えるでしょう。 – Evk
「サーバーにtelnet接続すると...」どうやってこれを行うのですか? –