duansengcha9114 2011-06-17 19:15
浏览 68
已采纳

有没有办法“收听”到Telnet流?

I just want a simple way of seeing what the last two lines in the Telnet stream were. For instance, if you can imagine a Terminal window, I just want to be able to type a command, hit enter, then see what the response is. So far, I can execute the command, but I'm having trouble evaluating the response. Rather than just the two lines of response being returned, stream_get_line returns every line from the stream.

Can anyone suggest a function or possibly a better way to write it?

$con = @pfsockopen("10.30.96.55", 23, $errno, $errstr, 30);

fputs($con, "ipaddress get");

while (!feof($con)) { 
    $response = stream_get_line($con, 100, "
"); 
} 

echo $response;

It may be that I don't completely understand stream_get_line(); if I'm doing something dumb, someone please help me out. Thanks!

  • 写回答

1条回答 默认 最新

  • duanaiguang1960 2011-06-20 14:10
    关注

    After more experimentation with fgets(), I have been able to achieve the desired affect.

    Rather than:

    while (!feof($con)) { 
        $response = stream_get_line($con, 100, "
    "); 
    } 
    

    I used:

    while (($buffer = fgets($con, 5)) !== false) {
        $total .= $buffer;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试