无法通过telnet PHP登录服务器

时间:2014-12-16 17:23:40

标签: php login telnet

我使用[PHP Telnet类] [1]通过telnet连接到服务器以发送命令。它成功连接到服务器但无法登录..

require_once "PHPTelnet.php";

$telnet = new PHPTelnet();

// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1

$result = $telnet->Connect('172.20.66.100','username','password');

if ($result == 0) {
   $telnet->DoCommand('another command', $result);

   echo $result;
   $telnet->Disconnect();}

=============================================== ================================  更新: 我的脚本正在运行,我的虚拟机发生了一些冲突......

2 个答案:

答案 0 :(得分:0)

试试这个:

    $url = 'tcp://ADDRESS_HERE:PORT_HERE';
    $fp = stream_socket_client($url, $errno, $errstr, 10);
    if (!$fp) {
        echo ("$errstr ($errno)<br />\n");
        exit;
    } else {
        $command = 'execute_command_line' . PHP_EOL;
        fwrite($fp, $out);

        stream_set_blocking($fp, true);

        while (!feof($fp)) {
            $output = stream_get_contents($fp);
        }

        fclose($fp);
        echo output;
    }

答案 1 :(得分:0)

根据PHPTelnet网站上的文档,您可以按错误的顺序获取构造函数的参数。

在图书馆的文档中有以下示例:

$result = $telnet->Connect('www.somewhere.com','login name','password');

因此,您应该:

$result = $telnet->Connect('172.20.66.100','username','password');

来源:PHPTelnet Documentation

修改

你提到你得到的错误3.在源代码中,错误3有以下描述:连接失败:登录失败

指向以下网址: Information about Error 3

其中列出了可能的原因:

  • 您错误拼写了用户名或密码(即您的凭据错误)
  • 您的用户名和密码无法使用Telnet服务(即您的用户无权访问Telnet服务)