首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP连接到Telnet服务器

PHP连接到Telnet服务器
EN

Stack Overflow用户
提问于 2018-07-18 03:53:09
回答 1查看 3K关注 0票数 1

我需要连接到服务器并通过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数据来发布我的用户名和密码?

EN

回答 1

Stack Overflow用户

发布于 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51389247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档