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

1.8k views Asked by At

I'm trying to connect and send command to a TCP server (I think it's 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. 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 #?

Wireshark print: print

2

There are 2 answers

5
Michael Schönbauer On

this is an example for Sockets, which is one way of sending and receiving data by TCP. You can change adress and port, and request text, and it should already be a working example.

Socket Class (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);

3
Mangesh Gaherwar On

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