91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么用php實現telnet

發布時間:2021-10-27 09:04:34 來源:億速云 閱讀:154 作者:iii 欄目:編程語言

這篇文章主要介紹“怎么用php實現telnet”,在日常操作中,相信很多人在怎么用php實現telnet問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么用php實現telnet”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

1、創建一個PHP示例文件。

2、通過“class PHPTelnet {function Connect($server,$user,$pass) {...}}”方式實現telnet功能即可。

實例

<?php
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 5
 
    var $sleeptime=125000;
 
    var $loginsleeptime=1000000;
 
    var $fp=NULL;
 
    var $loginprompt;
 
    var $conn1;
 
    var $conn2;
 
    /*
 
    0 = success
 
    1 = couldn't open network connection
 
    2 = unknown host
 
    3 = login failed
 
    4 = 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\n");
 
                $this->Sleep();
 
                fputs($this->fp,"$pass\n");
 
                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\n");
 
            $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, 1024);
 
            $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] 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 server\'s PHP version is too low for PHP Telnet
'; break;
 
        }
 
    }
 
}
 
?>

到此,關于“怎么用php實現telnet”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

哈密市| 郓城县| 金湖县| 天津市| 修文县| 镇原县| 汽车| 饶平县| 巴里| 隆回县| 周口市| 丹凤县| 监利县| 中宁县| 海口市| 阳新县| 临泽县| 冷水江市| 随州市| 玉林市| 浑源县| 宣恩县| 临洮县| 晋州市| 库伦旗| 汉寿县| 舞阳县| 南部县| 嘉义市| 皋兰县| 根河市| 迭部县| 略阳县| 西充县| 漯河市| 广宗县| 扎鲁特旗| 郁南县| 丰原市| 义乌市| 宣威市|