您的位置主页 > 编程专区 > Php > PHP Telnet Class

PHP Telnet Class

2009-10-15    文章来源:互联网    浏览次数:1607     分享文章

Official Site:

http://www.geckotribe.com/php-telnet/

Location Download:

Click to download PHP Telnet

Official Download:


Click to download PHP Telnet

 

Security:


I strongly recommend that you do not store your username and password in a PHP script unless only people you trust completely have access to your server. Instead, use a form to enter the username and password each time the script is run. Exercise caution with any system that transmits passwords over unencrypted connections.

 

Usage Examples:


Basic usage
NOTE: With PHP Telnet versions before 1.1, the following code will not display error messages for certain types of connection failures. If you are using an older version, either upgrade to the current version or use the next code example.

 
  1. <?php
  2. require_once "PHPTelnet.php";
  3.  
  4. $telnet = new PHPTelnet();
  5.  
  6. // if the first argument to Connect is blank,
  7. // PHPTelnet will connect to the local host via 127.0.0.1
  8. $result = $telnet->Connect('www.somewhere.com','login name','password');
  9.  
  10. if ($result == 0) { 
  11.     $telnet->DoCommand('enter command here'$result);
  12.     // NOTE: $result may contain newlines
  13.     echo $result;
  14.     $telnet->DoCommand('another command'$result);
  15.     echo $result;
  16.     // say Disconnect(0); to break the connection without explicitly logging out
  17.     $telnet->Disconnect(); 
  18. }
  19. ?> 

Display your own error messages
NOTE: With PHP Telnet versions before 1.1, the show_connect_error option was not supported. If you are using an older version, either upgrade to the current version, or delete the line that sets show_connect_error.

 
  1. <?php
  2. require_once "PHPTelnet.php";
  3.  
  4. $telnet = new PHPTelnet();
  5. $telnet->show_connect_error=0;
  6.  
  7. // if the first argument to Connect is blank,
  8. // PHPTelnet will connect to the local host via 127.0.0.1
  9. $result = $telnet->Connect('www.somewhere.com','login name','password');
  10.  
  11. switch ($result) {
  12.     case 0: 
  13.         $telnet->DoCommand('enter command here'$result);
  14.         // NOTE: $result may contain newlines
  15.         echo $result;
  16.         $telnet->DoCommand('another command'$result);
  17.         echo $result;
  18.         // say Disconnect(0); to break the connection without explicitly logging out
  19.         $telnet->Disconnect();
  20.         break
  21.     case 1:
  22.         echo '[PHP Telnet] Connect failed: Unable to open network connection';
  23.         break
  24.     case 2:
  25.         echo '[PHP Telnet] Connect failed: Unknown host';
  26.         break
  27.     case 3:
  28.         echo '[PHP Telnet] Connect failed: Login failed';
  29.         break
  30.     case 4:
  31.         echo '[PHP Telnet] Connect failed: Your PHP version does not support PHP Telnet';
  32.         break
  33. }
  34. ?> 

 

文章评论(查看全部)

昵 称 *
电子邮箱 *
网 址      1 + 3 = ?