有没有办法“监听”到 Telnet 流?
我只是想要一种简单的方法来查看 Telnet 流中的最后两行是什么。例如,如果您可以想象一个终端窗口,我只想能够键入命令,按 Enter 键,然后查看响应是什么。到目前为止,我可以执行该命令,但在评估响应时遇到困难。 stream_get_line
返回流中的每一行,而不是仅返回两行响应。
任何人都可以建议一个函数或可能更好的编写方法吗?
$con = @pfsockopen("10.30.96.55", 23, $errno, $errstr, 30);
fputs($con, "ipaddress get\r");
while (!feof($con)) {
$response = stream_get_line($con, 100, "\n");
}
echo $response;
可能是我没有完全理解stream_get_line()
;如果我做了一些愚蠢的事情,请有人帮助我。谢谢!
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\r");
while (!feof($con)) {
$response = stream_get_line($con, 100, "\n");
}
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过对
fgets()
的更多实验,我已经能够达到预期的效果。而不是:
我用的是:
After more experimentation with
fgets()
, I have been able to achieve the desired affect.Rather than:
I used: