0

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

João Soares
  • 49
  • 1
  • 12

2 Answers2

0

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);

  • I already tried socket and TCPClient. But it's apparently not possible to send the command in plain text. I need to send the command in plain text.. – João Soares Aug 27 '20 at 16:45
  • Thats exactly the code then. Its ASCII. Replace the content of `request` with your text, adjust address and port, and run the program. Wireshark should show plain text. – Michael Schönbauer Aug 28 '20 at 05:17
  • No.. the Encoding.ASCII convert the string to ASCII. Monitoring with Wireshark shows the ASCII code.. not the plain text. – João Soares Aug 28 '20 at 12:10
  • Encoding.ascii converts a string to a byte array. Every ASCII character is represented by a byte value between 0 and 255.. its the same.. 32 means space etc.. are you sure u are using wireshark correctly?? You could read the telnet rfc, its ASCII – Michael Schönbauer Aug 29 '20 at 13:19
  • Hi Michael. I figured out the problem. The Wireshark data is correct. The data is string hex. So I converted my string hex to byte array using this example: https://stackoverflow.com/questions/321370/how-can-i-convert-a-hex-string-to-a-byte-array – João Soares Aug 29 '20 at 15:34
0

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