执行 Telnet 握手
Perform a Telnet handshake
我正在编写一个(希望是简单的)控制台应用程序来向音频设备发送命令 运行 telnet。这些命令允许我更改其中包含的 DSP 组件的状态,例如:ToneGen set mute true
.
我遇到问题的地方是 telnet 握手,我知道有许多命令从 Telnet 服务器发送到客户端,客户端需要响应这些命令才能成功协商开始session。我只是不知道发送正确的命令。下面是我的一些不成功的尝试。
这是我目前的代码:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace telnetTest
{
class Program
{
static void Main(string[] args)
{
IPAddress address = IPAddress.Parse("192.168.10.101");
int port = 23;
IPEndPoint endpoint = new IPEndPoint(address, port);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Console.WriteLine("Establishing Connection to {0}", address);
s.Connect(endpoint);
byte[] Bytes = Encoding.ASCII.GetBytes("0xFC[=10=]xFC[=10=]XFC");
s.Send(Bytes);
byte[] buffer = new byte[50];
s.Receive(buffer);
Console.WriteLine(Encoding.ASCII.GetString(buffer));
Console.ReadKey();
}
}
}
代码输出如下:
Establishing Connection to 192.168.10.101
??↑?? ??#??'??$
所以我认为这里有两个核心问题:
1) 如何检测来自音频设备的握手请求
2) 如何发送适当的响应。
如有任何帮助,我们将不胜感激。
更新 1
byte[] buffer = new byte[1024];
int vari = s.Receive(buffer);
string hex1 = vari.ToString("X");
Console.WriteLine(hex1);
连接hex1后returns值为15
更新 2
Console.WriteLine("Sending Bytes");
byte[] Bytes1 = Encoding.ASCII.GetBytes("0xFF 0xFC 0x18 0xFF 0xFD 0x20 0xFF 0xFC 0x23 0xFF 0xFD 0x27 0xFF 0xFC 0x24 \n");
s.Send(Bytes1);
在上面的代码之后,我正在使用以下代码寻找来自服务器的下一个响应,
byte[] buffer2 = new byte[1024];
int byteCount2 = s.Receive(buffer2);
Console.WriteLine(byteCount2 + " Bytes Found");
我在控制台中看到的只是短语 "Sending Bytes",所以似乎 Bytes1
没有被发送并且没有进一步的响应字节要读取。
So I think I have two core issues here:
1) How to detect the handshake request from the audio device
2) How to send the appropriate response.
1) 如何检测来自音频设备的握手请求
byte[] buffer = new byte[1024];
int byteCount = s.Receive(buffer);
Console.WriteLine(byteCount + " Bytes Found");
DumpBytes(buffer, byteCount);
DumpBytes(buffer, byteCount);
在 MSDN 上找到的函数:link
在控制台 window 中显示 buffer
的内容,这对于检查连接后来自 telnet 服务器的响应很有用。
2) 如何发送适当的响应(返回到 telnet 服务器)。
var handshake1 = new byte[] { 0xFF, 0xFC, 0x18, 0xFF, 0xFC, 0x20, 0xFF, 0xFC, 0x23, 0xFF, 0xFC, 0x27, 0xFF, 0xFC, 0x24 };
s.Send(handshake1);
我正在编写一个(希望是简单的)控制台应用程序来向音频设备发送命令 运行 telnet。这些命令允许我更改其中包含的 DSP 组件的状态,例如:ToneGen set mute true
.
我遇到问题的地方是 telnet 握手,我知道有许多命令从 Telnet 服务器发送到客户端,客户端需要响应这些命令才能成功协商开始session。我只是不知道发送正确的命令。下面是我的一些不成功的尝试。
这是我目前的代码:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace telnetTest
{
class Program
{
static void Main(string[] args)
{
IPAddress address = IPAddress.Parse("192.168.10.101");
int port = 23;
IPEndPoint endpoint = new IPEndPoint(address, port);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Console.WriteLine("Establishing Connection to {0}", address);
s.Connect(endpoint);
byte[] Bytes = Encoding.ASCII.GetBytes("0xFC[=10=]xFC[=10=]XFC");
s.Send(Bytes);
byte[] buffer = new byte[50];
s.Receive(buffer);
Console.WriteLine(Encoding.ASCII.GetString(buffer));
Console.ReadKey();
}
}
}
代码输出如下:
Establishing Connection to 192.168.10.101
??↑?? ??#??'??$
所以我认为这里有两个核心问题:
1) 如何检测来自音频设备的握手请求 2) 如何发送适当的响应。
如有任何帮助,我们将不胜感激。
更新 1
byte[] buffer = new byte[1024];
int vari = s.Receive(buffer);
string hex1 = vari.ToString("X");
Console.WriteLine(hex1);
连接hex1后returns值为15
更新 2
Console.WriteLine("Sending Bytes");
byte[] Bytes1 = Encoding.ASCII.GetBytes("0xFF 0xFC 0x18 0xFF 0xFD 0x20 0xFF 0xFC 0x23 0xFF 0xFD 0x27 0xFF 0xFC 0x24 \n");
s.Send(Bytes1);
在上面的代码之后,我正在使用以下代码寻找来自服务器的下一个响应,
byte[] buffer2 = new byte[1024];
int byteCount2 = s.Receive(buffer2);
Console.WriteLine(byteCount2 + " Bytes Found");
我在控制台中看到的只是短语 "Sending Bytes",所以似乎 Bytes1
没有被发送并且没有进一步的响应字节要读取。
So I think I have two core issues here:
1) How to detect the handshake request from the audio device
2) How to send the appropriate response.
1) 如何检测来自音频设备的握手请求
byte[] buffer = new byte[1024];
int byteCount = s.Receive(buffer);
Console.WriteLine(byteCount + " Bytes Found");
DumpBytes(buffer, byteCount);
DumpBytes(buffer, byteCount);
在 MSDN 上找到的函数:link
在控制台 window 中显示 buffer
的内容,这对于检查连接后来自 telnet 服务器的响应很有用。
2) 如何发送适当的响应(返回到 telnet 服务器)。
var handshake1 = new byte[] { 0xFF, 0xFC, 0x18, 0xFF, 0xFC, 0x20, 0xFF, 0xFC, 0x23, 0xFF, 0xFC, 0x27, 0xFF, 0xFC, 0x24 };
s.Send(handshake1);