在Java中,可以使用Socket类来进行telnet操作。下面是一个示例代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class TelnetExample {

    public static void main(String[] args) {
        String host = "10.11.9.11";
        int port = 8002;

        try {
            // 创建Socket连接
            Socket socket = new Socket(host, port);

            // 获取输入流和输出流
            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter output = new PrintWriter(socket.getOutputStream());

            // 发送命令
            output.println("command");
            output.flush();

            // 读取响应
            String response;
            while ((response = input.readLine()) != null) {
                System.out.println(response);
            }

            // 关闭连接
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

请将hostport变量替换为实际的telnet服务器地址和端口。然后在output.println("command")中替换为实际要发送的命令。运行该代码,将会打印出telnet服务器返回的响应

java 怎么在代码中进行 telnet 10119118002

原文地址: https://www.cveoy.top/t/topic/ipxe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录