Barrie Eksteen

Barrie Eksteen

  • NA
  • 2
  • 2.2k

TELNET into Server

Apr 26 2013 3:17 AM

please help

I am trying to telnet into a zebra printer with C# and then run through the menu with values I supply and then want to be returned a value.

This is my code thus far: When I telnet with putty, I get prompted for a password, then after i put in the password I get the menu. So in my code I want to give the value "1234" as the password and I then want to be returned the menu. Please help Im stuck :(

public static void StartClient() {
// Data buffer for incoming data.
byte[] bytes = new byte[1024];
// Connect to a remote device.
try {
// Establish the remote endpoint for the socket.
// This example uses port 23 on the Server.
IPHostEntry ipHostInfo = Dns.Resolve("");//Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress,23);

// Create a TCP/IP  socket.
Socket sender = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp );

// Connect the socket to the remote endpoint. Catch any errors.
try {

Console.WriteLine("Socket connected to {0}",

// Encode the data string into a byte array.
byte[] msg = Encoding.ASCII.GetBytes("1234/n/r");

// Send the data through the socket.
int bytesSent = sender.Send(msg);

// Receive the response from the remote device.
int bytesRec = sender.Receive(bytes);
//Console.WriteLine("Echoed test = {0}",
//    Encoding.ASCII.GetString(bytes,0,bytesRec));

// Release the socket.

} catch (ArgumentNullException ane) {
Console.WriteLine("ArgumentNullException : {0}",ane.ToString());
} catch (SocketException se) {
Console.WriteLine("SocketException : {0}",se.ToString());
} catch (Exception e) {
Console.WriteLine("Unexpected exception : {0}", e.ToString());

} catch (Exception e) {
Console.WriteLine( e.ToString());