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!

图片转代码服务由CSDN问答提供 功能建议

我只是想要一种简单的方法来查看Telnet流中的最后两行是什么。 例如,如果你能想象一个终端窗口,我只想输入命令,点击回车,然后看看响应是什么。 到目前为止,我可以执行命令,但是我无法评估响应。 而不是只返回两行响应, stream_get_line 返回流中的每一行。

任何人都可以建议一个函数或者更好的方法来编写它 ?

  $ con = @pfsockopen(“10.30.96.55”,23,$ errno,$ errstr,30); 
 
 nfputs($ con,“ipaddress get \  r“); 
 
while(!feof($ con)){
 $ response = stream_get_line($ con,100,”
“);  
} 
 
echo $ response; 
   
 
 

可能我不完全理解 stream_get_line(); 如果我做某事愚蠢,有人请帮助我。 谢谢!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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;
    }
    
    打赏 评论

相关推荐 更多相似问题