前几天看了网上一个牛人写的php telnet的源码
<?php/*** name:薛如飞* qq:6706250* e-mail:xuerufei@163.com* blog:<a href="http://hi.baidu.com/" target="_blank">http://hi.baidu.com/</a>飞云盖天* 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->Disconnect(); 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 {?><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><form action="index.php" method="post" name="form0" id="form0"> <p> </p> <p align="center" >Telnet</p> <table width="200" border="0" align="center"> <tr> <td width="81" height="18">host:</td> <td width="109"><input name="host" type="text" size="16" value="" /></td> </tr> <tr> <td width="81" height="18">user:</td> <td width="109"><input name="user" type="text" size="16" value="" /></td> </tr> <tr> <td width="81" height="18">pass:</td> <td width="109"><input name="pass" type="text" size="16" value="" /></td> </tr> <tr> <td width="81" height="18">cmd:</td> <td width="109"> <textarea rows="6" name="cmd" cols="16"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="提交" /></td> </tr> </table> <p> </p></form><?php }?> <?php/*PHPTelnet 1.1by Antone Roundyadapted from code found on the PHP websitepublic domain*/class PHPTelnet {var $show_connect_error=1;var $use_usleep=0; // change to 1 for faster execution // don't change to 1 on Windows servers unless you have PHP 5var $sleeptime=125000;var $loginsleeptime=1000000;var $fp=NULL;var $loginprompt; var $conn1;var $conn2; /*0 = success1 = couldn't open network connection2 = unknown host3 = login failed4 = PHP version too low*/function Connect($server,$user,$pass) { $rv=0; $vers=explode('.',PHP_VERSION); $needvers=array(4,3,0); $j=count($vers); $k=count($needvers); if ($k<$j) $j=$k; for ($i=0;$i<$j;$i++) { if (($vers[$i]+0)>$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='127.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 '<br />[PHP Telnet] <a href="<a href="http://www.geckotribe.com/php-telnet/errors/fsockopen.php" target="_blank">http://www.geckotribe.com/php-telnet/errors/fsockopen.php">Connect</a> failed: Unable to open network connection</a><br />'; break; case 2: echo '<br />[PHP Telnet] <a href="<a href="http://www.geckotribe.com/php-telnet/errors/unknown-host.php" target="_blank">http://www.geckotribe.com/php-telnet/errors/unknown-host.php">Connect</a> failed: Unknown host</a><br />'; break; case 3: echo '<br />[PHP Telnet] <a href="<a href="http://www.geckotribe.com/php-telnet/errors/login.php" target="_blank">http://www.geckotribe.com/php-telnet/errors/login.php">Connect</a> failed: Login failed</a><br />'; break; case 4: echo '<br />[PHP Telnet] <a href="<a href="http://www.geckotribe.com/php-telnet/errors/php-version.php" target="_blank">http://www.geckotribe.com/php-telnet/errors/php-version.php">Connect</a> failed: Your server\'s PHP version is too low for PHP Telnet</a><br />'; break; }}}?>
我使用的是ubuntu 12.04的server版系统,自带的LAMP。然后再执行该程序的时候,一直报
[PHP Telnet] Connect failed: Login failed 的错误,
但是其他同事在其他电脑上面安装ubuntu 12.04,执行这套程序的时候却是正常工作的,弄了好几天,实在不知道是什么原因,恳请大牛解答,分数不多,就这么点了,多谢了!
回复讨论(解决方案)
其实我就是想在网页中嵌入一个 ssh或者telnet的远程登录程序。有其他的方法更好,多谢了
确认一下你和你同事的php版本
我觉得跟这个有关
\r换成\n,LINUX不认\r的

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment