(Online, etc.) for a phptelnet issue, I read the php telnet source code written by a cool man on the Internet a few days ago.
Apsara stack X date: 08.08.28 **/if (isset ($ _ POST ['host']) and isset ($ _ POST ['user']) {$ host = $ _ POST ['host']; $ user = $ _ POST ['user']; $ pass = $ _ POST ['pass']; $ cmd = stripslashes ($ _ POST ['cmd']); require_once "phptelnet. php "; $ telnet = new PHPTelnet (); $ telnet-> show_connect_error = 0; $ result = $ telnet-> Connect ($ host, $ user, $ pass ); switch ($ result) {case 0: $ telnet-> DoCommand ($ cmd, $ result); echo $ result; $ telnet-> Disco Nnect (); break; case 1: echo '[PHP Telnet] Connect failed: Unable to open network connection'; break; case 2: echo '[PHP Telnet] Connect failed: unknown host '; break; case 3: echo' [PHP Telnet] Connect failed: Login failed '; break; case 4: echo' [PHP Telnet] Connect failed: your PHP version does not support PHP Telnet '; break ;}} else {?>
$ Needvers [$ I]) break; if ($ vers [$ I] + 0) <$ needvers [$ I]) {$ this-> ConnectError (4 ); return 4 ;}$ this-> Disconnect (); if (strlen ($ server) {if (preg_match ('/[^ 0-9.] /', $ server) {$ ip = gethostbyname ($ server); if ($ ip = $ server) {$ ip = ''; $ rv = 2 ;}} else $ ip = $ server;} else $ ip = '2017. 0.0.1 '; if (strlen ($ ip) {if ($ this-> fp = fsockopen ($ ip, 23) {fputs ($ this-> fp, $ this-> conn1); $ this-> Sleep (); fputs ($ this-> Fp, $ this-> conn2); $ this-> Sleep (); $ this-> GetResponse ($ r); $ r = explode ("\ n ", $ r); $ this-> loginprompt = $ r [count ($ r)-1]; fputs ($ this-> fp, "$ user \ r "); $ this-> Sleep (); fputs ($ this-> fp, "$ pass \ r"); if ($ this-> use_usleep) usleep ($ this-> loginsleeptime); else sleep (1); $ this-> GetResponse ($ r); $ r = explode ("\ n", $ r ); if ($ r [count ($ r)-1] = '') | ($ this-> loginprompt = $ r [count ($ r) -1]) {$ rv = 3; $ this-> Disconnect ();}} Else $ rv = 1;} if ($ rv) $ this-> ConnectError ($ rv); return $ rv;} function Disconnect ($ exit = 1) {if ($ this-> fp) {if ($ exit) $ this-> DoCommand ('exit ', $ junk); fclose ($ this-> fp ); $ this-> fp = NULL;} function DoCommand ($ c, & $ r) {if ($ this-> fp) {fputs ($ this-> fp, "$ c \ r"); $ this-> Sleep (); $ this-> GetResponse ($ r); $ r = preg_replace ("/^. *? \ N (. *) \ n [^ \ n] * $/"," $1 ", $ r);} return $ this-> fp? 1:0;} function GetResponse (& $ r) {$ r = ''; do {$ r. = fread ($ this-> fp, 1000); $ s = socket_get_status ($ this-> fp);} while ($ s ['unread _ bytes ']);} function Sleep () {if ($ this-> use_usleep) usleep ($ this-> sleeptime); else sleep (1);} function PHPTelnet () {$ this-> conn1 = 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); $ this-> conn2 = chr (0xFF ). chr (0xFC ). chr (0x01 ). chr (0xFF ). chr (0xFC ). chr (0x22 ). chr (0xFF ). chr (0xFE ). chr (0x05 ). chr (0xFF ). chr (0xFC ). chr (0x21);} function ConnectError ($ num) {if ($ this-> show_connect_error) switch ($ num) {case 1: echo'
[PHP Telnet] http://www.geckotribe.com/php-telnet/errors/fsockopen.php "> Connect failed: Unable to open network connection
'; Break; case 2: echo'
[PHP Telnet] http://www.geckotribe.com/php-telnet/errors/unknown-host.php "> Connect failed: Unknown host
'; Break; case 3: echo'
[PHP Telnet] http://www.geckotribe.com/php-telnet/errors/login.php "> Connect failed: Login failed
'; Break; case 4: echo'
[PHP Telnet] http://www.geckotribe.com/php-telnet/errors/php-version.php "> Connect failed: Your server \'s PHP version is too low for PHP Telnet
'; Break ;}}?>
I am using the server version of ubuntu 12.04 and the built-in LAMP. When the program is executed
[PHP Telnet] Connect failed: Login failed error,
However, when other colleagues installed ubuntu 12.04 on other computers, they were working normally during the execution of this program. after several days, I really don't know why. I 'd like to ask Daniel to answer this question, that's all. thank you!
Reply to discussion (solution)
In fact, I just want to embed an ssh or telnet remote login program in the webpage. Other methods are better. thank you.
Confirm your php version with your colleagues
I think it is related to this.
Replace \ r with \ n. If LINUX does not recognize \ r