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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?