【发布时间】:2018-12-25 14:52:48
【问题描述】:
我需要连接到服务器并通过 Telnet 发送命令,但在查找如何通过授权连接时遇到了一些麻烦。
我已经使用以下脚本连接,但我仍然需要输入用户名和密码才能访问。
<?php
$host="xxxxxxxxxxx";
$port = xxxxxxxxxx; // open a client connection
$fp = fsockopen ($host, $port, $errno, $errstr);
if (!$fp) {
$result = "Error: could not open socket connection";
}
else { // get the welcome message fgets ($fp, 1024); // write the user string to the socket
fputs($fp, $message); // get the result $result .= fgets ($fp, 1024); // close the connection
fputs ($fp, "END");
fclose ($fp); // trim the result and remove the starting ?
$result = trim($result);
$result = substr($result, 2); // now print it to the browser
} ?>
Server said: <? echo $result; ?>
?>
我一直在四处寻找,甚至在 PHP 文档上,但没有看到使用密码和用户名的方法。
我必须使用 POST 数据来发布我的用户名和密码吗?
【问题讨论】:
-
TELNET 协议 RFC tools.ietf.org/html/rfc854
-
在输入之前是否需要等待提示出现?见stackoverflow.com/a/6280342/5947043。附言POST数据是什么意思?据我所知,这是一个 HTTP 概念,而不是 telnet。当然,如果套接字上的侦听器是 HTTP 服务器,您可以使用 telnet 连接发送 HTTP 命令,但那是另一回事了。你没有提到你正在连接什么服务或你想要发送什么样的命令
-
@ADyson 这是我在游戏服务器上运行的 VPS。游戏服务器使用 Telnet。
-
Telnet 只是打开一个 TCP 连接。之后您必须使用某些特定的协议来交换消息?有一个用于简单消息的基本 telnet 协议,但您无能为力。可能有一些进一步商定的格式用于构建消息。