我需要连接到服务器并通过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数据来发布我的用户名和密码?
发布于 2018-07-18 04:51:54
正如其他人已经说过的那样,telnet只是打开一个到服务器的套接字。这也是对fsockopen()的调用。您要连接的服务应该对您下一步要做的事情有一个定义。
假设连接到FTP服务器。一旦建立了连接,您就可以将LIST命令写入套接字。服务器将识别该命令,并将文件列表发送回您的套接字。
在您的情况下,您的交换可能类似于:
write: AUTH
read: OK
write: USERNAME username
read: OK
write PASSWORD password
read: STATUS OK
https://stackoverflow.com/questions/51389247
复制相似问题