Telnet接続やコマンドの転送、戻り値の取得などを実現するためにPHPが使われています!

WBOY
リリース: 2016-07-25 08:43:11
オリジナル
1351 人が閲覧しました

php来实现telnet的的连接、、、传递命令、返回值等等功能

  1. <?php
  2. error_reporting(-1);
  3. classtelnet {
  4. bar $ sock = null; $host,$port) {
  5. $this->sock = fsockopen($host,$port);
  6. socket_set_timeout($this->sock,2,0);
  7. }
  8. function close() {
  9. if ($this->sock) fclose($this->sock);
  10. $this->sock = NULL;
  11. }
  12. function write($buffer) {
  13. $buffer = str_replace(chr(255), chr(255).chr(255),$buffer);
  14. fwrite($this->sock,$buffer);
  15. }
  16. function getc() {
  17. return fgetc($this->sock);
  18. }
  19. 関数 read_till($what) {
  20. $buf = '';
  21. while (1) {
  22. $IAC = chr(255);
  23. $DONT = chr(254);
  24. $DO = chr(253) ;
  25. $WONT = chr(252);
  26. $WILL = chr(251);
  27. $theNULL = chr(0);
  28. $c = $this->getc();
  29. if ($c === false) return $buf;
  30. if ($c == $theNULL) {
  31. continue;
  32. }
  33. if ($c == "1") {
  34. continue;
  35. }
  36. if ($c ! = $IAC) {
  37. $buf .= $c;
  38. if ($what == (substr($buf,strlen($buf)-strlen($what)))) {
  39. return $buf;
  40. }
  41. else {
  42. continue;
  43. }
  44. }
  45. $c = $this->getc();
  46. if ($c == $IAC) {
  47. $buf .= $c;
  48. }
  49. else if (( $c == $DO) || ($c == $DONT)) {
  50. $opt = $this->getc();
  51. // echo "".ord($opt)."n";
  52. fwrite($this->gt; sock,$IAC.$WONT.$opt);
  53. }
  54. elseif (($c == $WILL) || ($c == $WONT)) {
  55. $opt = $this->getc();
  56. // echo "我々は ".ord($opt)."n";
  57. fwrite($this->sock,$IAC.$DONT.$opt);
  58. }
  59. else {
  60. // echo "where c=".ord($c)."n";
  61. }
  62. }
  63. }
  64. }
  65. /*
  66. $telnet = new telnet("192.168.0.1",23);
  67. echo $telnet- >read_till("ログイン: ");
  68. $telnet->write("kongxxrn");
  69. echo $telnet->read_till("パスワード: ");
  70. $telnet->write("KONGXXrn") ;
  71. echo $telnet->read_till(":> ");
  72. $telnet->write("lsrn");
  73. echo $telnet->read_till(":> ");
  74. echo $telnet ->close();
*/
复制代

等機能、来实现、返值


🎜
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!