doubeng9567 2014-12-16 17:23
浏览 157

无法通过telnet PHP登录服务器

I'm using a [PHP Telnet Class][1] to connect to server via telnet to send commands. It connects to the server successfully but it fails to login in..

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();}

=============================================================================== UPDATE: My script is working, there was some conflict going on with my virtual machine......

  • 写回答

2条回答

  • dongyu3659 2014-12-16 17:35
    关注

    Try this:

        $url = 'tcp://ADDRESS_HERE:PORT_HERE';
        $fp = stream_socket_client($url, $errno, $errstr, 10);
        if (!$fp) {
            echo ("$errstr ($errno)<br />
    ");
            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;
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制