gpt4 book ai didi

PHP 从 Windows 机器上的套接字读取

转载 作者:行者123 更新时间:2023-12-03 12:06:04 25 4
gpt4 key购买 nike

我正在尝试编写一个“简单”的 PHP 程序,该程序应该向/从套接字(端口 23 上的 telnet)写入和读取字符串。

套接字连接是使用 pfsockopen(或 socket_connect)函数进行的,它似乎可以正常工作(使用 wireshark 验证)。
问题是当我尝试使用 fread 或 socket_read 从套接字读取时。
这两个函数返回的缓冲区是不可读的(没有文本,只有特殊的 ascii 字符)。

考虑 php 脚本在 Windows XP PC 上运行。
你知道在 Windows PC 和 telnet 协议(protocol)上使用这些库有什么限制吗?

    $header1=chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0);

$fp=pfsockopen("10.129.127.33",23);
fputs($fp,$header1);
sleep(1);
$output=fread($fp,8164);
echo $output;

最佳答案

  • 连接成功了吗?
  • 服务器是否允许在端口 23 上连接?
  • 这可能会对您有所帮助

  • fputs($fp,"字符串");
    do 
    {
    $output.=fread($fp, 80);
    // read line by line, or at least small chunks
    $stat=socket_get_status($fp);
    }
    while($stat["unread_bytes"]);

    $output = str_replace("\n", "<br>", $output);\\for new line in HTML
    echo $output;
  • 以下是我使用的 TELNET header
    $header1=chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).ch.(0x01).chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0);
    $header2=chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21);

    $fp=fsockopen("192.168.125.6",23);


    //**********Send telnet header****************

    fputs($fp,$header1);

    usleep(1000);

    fputs($fp,$header2);

    usleep(1000);
  • 关于PHP 从 Windows 机器上的套接字读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10799890/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com