请帮助TELNET进入服务器 [英] Please help with TELNET into Server
本文介绍了请帮助TELNET进入服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助
我试图用C#远程登录斑马打印机,然后使用我提供的值运行菜单,然后想要返回一个值。
这是我的代码到目前为止:当我使用putty进行远程登录时,系统会提示输入密码,然后在我输入密码后,我会收到菜单。所以在我的代码中,我想给出值1234作为密码,然后我想返回菜单。请帮助我卡住了:(
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("10.121.237.151");//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 {
sender.Connect(remoteEP);
Console.WriteLine("Socket connected to {0}",
sender.RemoteEndPoint.ToString());
// 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(msg.ToString());
//Console.WriteLine("Echoed test = {0}",
// Encoding.ASCII.GetString(bytes,0,bytesRec));
//Console.ReadLine();
// Release the socket.
sender.Shutdown(SocketShutdown.Both);
sender.Close();
Console.ReadLine();
} catch (ArgumentNullException ane) {
Console.WriteLine("ArgumentNullException : {0}",ane.ToString());
Console.ReadLine();
} catch (SocketException se) {
Console.WriteLine("SocketException : {0}",se.ToString());
Console.ReadLine();
} catch (Exception e) {
Console.WriteLine("Unexpected exception : {0}", e.ToString());
Console.ReadLine();
}
} catch (Exception e) {
Console.WriteLine( e.ToString());
Console.ReadLine();
}
}
推荐答案
坚持什么?你还没有解释你的问题。但是,您可能需要编写正确的Telnet客户端,而不是仅使用简单的套接字交换;请参阅 http://tools.ietf.org/html/rfc854 [ ^ ]有关协议的详细信息。
Stuck with what? You have not explained what your problem is. However, you may need to write a proper Telnet client rather than just use a simple socket exchange; see http://tools.ietf.org/html/rfc854[^] for details of the protocol.
我想要做的是,在我的代码中将服务器密码发送到服务器,选择我在连接putty时会看到的菜单项,然后为我返回一个值,我会在菜单中看到...这可能吗?
what I want to do is, in my code send the server password to the server, select a menu item that I would see when connecting with putty, and then return a value for me that i would see in the menu...is that possible?
这篇关于请帮助TELNET进入服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文