简体   繁体   English

C# - 向 Telnet 服务器发送命令(纯文本)

[英]C# - Send command to Telnet Server (Plain Text)

I'm trying to connect and send command to a TCP server (I think it's Telnet).我正在尝试连接并向 TCP 服务器发送命令(我认为是 Telnet)。 All I know is I need to send commands to receive data.我所知道的是我需要发送命令来接收数据。

We already have a reader on our local network, but it's very old and does not have all the functions we need.我们的本地网络上已经有一个阅读器,但它很旧,没有我们需要的所有功能。 To monitor the reader, I installed Wireshark.为了监控阅读器,我安装了 Wireshark。 Where it showed that the command sent is in plain text.它显示发送的命令是纯文本的。 And there's no authentication.而且没有身份验证。

So I just need to connect, without authentication and send the command in plain text.所以我只需要连接,无需身份验证并以纯文本形式发送命令。 How to connect to a Telnet server using C #?如何使用 C# 连接到 Telnet 服务器?

Wireshark print : print Wireshark 打印打印

this is an example for Sockets, which is one way of sending and receiving data by TCP.这是 Sockets 的一个例子,它是 TCP 发送和接收数据的一种方式。 You can change adress and port, and request text, and it should already be a working example.您可以更改地址和端口,并请求文本,它应该已经是一个工作示例。

Socket Class (System.Net.Socket) 套接字类 (System.Net.Socket)

If the thing you need to send are bytes instead of text, you can fill the sent byte array manually instead of decoding a string into a byte array in the line Byte[] bytesSent = Encoding.ASCII.GetBytes(request);如果您需要发送的是字节而不是文本,您可以手动填充发送的字节数组,而不是在Byte[] bytesSent = Encoding.ASCII.GetBytes(request);Byte[] bytesSent = Encoding.ASCII.GetBytes(request);字符串解码为字节数组Byte[] bytesSent = Encoding.ASCII.GetBytes(request);

Honestly you cannot send plain text you need to convert your plain text into byte array an then write that array to the port老实说,您无法发送纯文本,您需要将纯文本转换为字节数组,然后将该数组写入端口

This has example how we should do this这有我们应该如何做到这一点的例子

Server Client send/receive simple text 服务器客户端发送/接收简单文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM