【发布时间】:2014-06-11 12:30:51
【问题描述】:
我正在尝试使用 telnet 进行连接,但服务器的响应是一个不可读的字符串,有人可以帮助我吗? (telnet 服务器是 windows XP),我想通过 telnet 进行身份验证并执行一些命令。 以下代码如下
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.Socket;
public class TelnetClient {
public static void main(String args[]) throws Exception{
// Create object of Socket
Socket soc = new Socket("192.168.56.101", 23);
String Command;
// Create object of Input Stream to read from socket
DataInputStream din = new DataInputStream(soc.getInputStream());
// Create object of Output Stream to write on socket
DataOutputStream dout = new DataOutputStream(soc.getOutputStream());
// Object of Buffered Reader to read command from terminal
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Welcome to Telnet Client");
System.out.println("< Telnet Prompt >");
Command = br.readLine();// reads the command
dout.writeUTF(Command);// sends command to server
System.out.println(din.readLine()); // gets the response of server
soc.close(); // close port
din.close(); // close input stream
dout.close(); // close output stream
br.close(); // close buffered Reader
}
}
服务器的响应是:ÿý%ÿûÿûÿý'ÿýÿý 有很多“?”
【问题讨论】: