2
我想通过CLI在Windows 7中运行此PHP脚本。
测试背景
为了建立SSH一个具有发送和接收的横幅消息。您向服务器发送“SSH-2.0-whatever \ r \ n”,服务器将您发送回“SSH-2.0-whatever \ r \ n”(这也可以以其他方式完成),然后您收到一条消息包含服务器支持的算法。即。
(脚本1)
<?php
$fsock = fsockopen('shell.sourceforge.net', 22);
echo fgets($fsock, 1024);
fputs($fsock, "SSH-2.0-test\r\n");
echo fread($fsock, 1024);
下面是输出:
SSH-2.0-OpenSSH_5.3
♥♀
¶ólÆƧw↔F;ï÷╝ähºv ~diffie-hellman-group-exchange-sha256,diffie-hellman-group-e
xchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 ☼ssh-rsa,s
sh-dss ¥aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des
-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
.liu.se ¥aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3de
s-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
r.liu.se ihmac-md5,hmac-sha1,[email protected],hmac-ripemd160,hmac-ripemd160
@openssh.com,hmac-sha1-96,hmac-md5-96 ihmac-md5,hmac-sha1,[email protected],
hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96 §none,[email protected]
openssh.com §none,[email protected]
代码,以便给出上述好像这两个脚本输出
,运行一个之后,应该给出相同的输出:
(脚本2)
<?php
$fsock = pfsockopen('shell.sourceforge.net', 22);
echo fgets($fsock, 1024);
(脚本3)
<?php
$fsock = pfsockopen('shell.sourceforge.net', 22);
fputs($fsock, "SSH-2.0-test\r\n");
echo fread($fsock, 1024);
不幸的是,脚本1不匹配脚本2和脚本3相结合。脚本3似乎正在运行,就好像脚本2从未做过一样。输出:
SSH-2.0-OpenSSH_5.3
SSH-2.0-OpenSSH_5.3
为什么它不工作?