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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退