如何使用 fsockopen() 打开带有密码的 Telnet 连接? [英] How do I use fsockopen() to open a Telnet connection with a password?

查看:26
本文介绍了如何使用 fsockopen() 打开带有密码的 Telnet 连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过它的 Telnet 功能访问相机.问题是,它有密码保护.通过终端执行此操作时没有问题,因为我只使用 telnet 10.30.blah.blah 然后在出现提示时输入我的密码.但是在php中,我看不到输入密码的机会.

I'd like to access a camera through it's Telnet capability. The problem is, it has Password-protection. This is no problem when doing it via Terminal, as I just use telnet 10.30.blah.blah then enter my password when prompted. But in php, I don't see the opportunity to input a password.

$con = fsockopen("10.30.blah.blah", 25);
$msg = "camera move left";
fwrite($con, $msg);

有人有什么想法吗?

更新:我试着像@Cfreak 所说的那样使用 fputs 输出密码,但仍然无济于事.如果我完全按照脚本在终端中尝试执行的操作,它就可以工作.现在是代码:

UPDATE: I tried just using fputs to output the password as @Cfreak said, but still to no avail. If I do exactly what the script is trying in terminal, it works. Here's the code now:

$con = fsockopen("10.30.blah.blah", 23, $errno, $errstr, 30);
$pass = "admin";
sleep(5);
fputs($con, $pass);
sleep(5);
$msg = "camera move left";
fputs($con, $msg);

UPDATE:发现我的 $msg 变量末尾需要一个 \r.感谢您的帮助!

UPDATE: Found that I needed a \r at the end of my $msg variable. Thanks for the help!

推荐答案

你只需输出它.我见过的一些示例使用 fputs.您可能需要睡一会才能确保出现提示.fsockopen 手册页的注释中实际上有一个示例:http://php.net/manual/en/function.fsockopen.php

You just output it. Some examples I've seen use fputs. You might have to sleep for a second to make sure the prompt comes up. There's actually an example in the comments on the fsockopen manual page: http://php.net/manual/en/function.fsockopen.php

虽然我真的建议寻找一个可以做到这一点的模块.一个快速的谷歌显示有几个.我不想推荐一个特定的,因为我没有使用过任何一个.

Really though I'd recommend looking for a module that does this. A quick google shows there are several out there. I don't want to recommend a particular one because I haven't used any of them.

这篇关于如何使用 fsockopen() 打开带有密码的 Telnet 连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆