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 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 Ubuntu20.04无法连接GitHub
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥30 C++行情软件的tick数据如何高效的合成K线