【问题标题】:PHp fsockopen() communicating via Telnetphp fsockopen() 通过 Telnet 通信
【发布时间】:2011-10-30 02:23:16
【问题描述】:

我正在寻找有关如何使用fsockopen() 与 telnet 系统进行通信的指南……我连接得很好,但是命令发送失败。我看过一些文档 fwrite() 显示人们发送了一些标头。

目前我对 telnet 服务器运行的命令是 version via $class->send("version");。我是否需要发送标头或其他任何内容以供 telnet 服务器接收命令,或者我可以直接发送吗?

/**
 * Connect to the GMC telnet system
 */
public function connect () {
    $this->connection = fsockopen($this->socket['host'], $this->socket['port'], $errorNumber, $errorMessage, 30);
    if (!$this->connection) {
        $this->error = 'Unable to connect to GMC: '.$errorMessage.' ('.$errorNumber.')';
        return false;
    }
    stream_set_timeout($this->connection, $this->commandTimeout);
    return true;
}

/**
 * Send a command to GMC
 */
public function send ($command) {
    //write to socket
    if (fwrite($this->connection, $command) === false) {
        $this->error = 'Unable to write to socket';
        return false;
    }

    sleep(1);

    //read socket
    if (($response = fgets($this->connection)) === false) {
        $this->error = 'Unable to write to socket';
        return false;
    }

    return $response;
}

/**
 * Disconnects from the GMC telnet system
 */
public function disconnect () {
    return fclose($this->connection);
}

【问题讨论】:

  • 一个 telnet 服务器意味着您正在使用远程 shell 帐户...您为此完成了登录过程吗?您不能只连接到 telnet 并开始发出命令 - 在进入 shell 阶段之前,它首先需要一个用户名/密码。
  • 我通过本地机器连接到 telnet,它没有要求输入用户名或密码。这是在没有用户连接到的唯一本地服务器上,只有应用程序。
  • 即使它只是在您的机器上,也有一个 telnet 端口可以进行登录。您应该发送的第一件事是用户名/密码,带有\n 表示您已完成输入。

标签: php telnet fsockopen


【解决方案1】:

显然,我需要做的就是确保在命令末尾包含\n!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-14
    • 2019-01-01
    • 2012-08-11
    • 2017-07-26
    • 2014-04-13
    • 2011-11-18
    • 2012-02-15
    相关资源
    最近更新 更多