Instead of performing a send for each stroke, the user code type in a whole
string in a text box, and then submit that string. I have found this code at
http://www.phpbuilder.com/mail/php-general/2001051/1479.php:

<?
error_reporting(-1);


class Telnet {
        /* (c) [EMAIL PROTECTED] */


        var $sock = NULL;


        function telnet($host,$port) {
        $this->sock = fsockopen($host,$port);
                socket_set_timeout($this->sock,2,0);
        }


    function close() {
        if ($this->sock)
            fclose($this->sock);
        $this->sock = NULL;
        }


    function write($buffer) {
                $buffer = str_replace(chr(255),chr(255).chr(255),$buffer);
        fwrite($this->sock,$buffer);
        }


        function getc() {
                return fgetc($this->sock);
        }


    function read_till($what) {
        $buf = '';
                while (1) {
                        $IAC = chr(255);


                        $DONT = chr(254);
                        $DO = chr(253);


                        $WONT = chr(252);
                        $WILL = chr(251);


                        $theNULL = chr(0);


                        $c = $this->getc();


                        if ($c === false)
                          return $buf;


                        if ($c == $theNULL) {
                                continue;
                        }


                        if ($c == "\021") {
                                continue;
                        }


                        if ($c != $IAC) {
                                $buf .= $c;


                                if ($what ==
(substr($buf,strlen($buf)-strlen($what)))) {
                                        return $buf;
                                } else {
                                        continue;
                                }
                        }


                        $c = $this->getc();


                        if ($c == $IAC) {
                                $buf .= $c;
                        } else if (($c == $DO) || ($c == $DONT)) {
                                $opt = $this->getc();
                        // echo "we wont ".ord($opt)."\n";
                                fwrite($this->sock,$IAC.$WONT.$opt);
                        } elseif (($c == $WILL) || ($c == $WONT)) {
                                $opt = $this->getc();
                        // echo "we dont ".ord($opt)."\n";
                                fwrite($this->sock,$IAC.$DONT.$opt);
                        } else {
                        // echo "where are we? c=".ord($c)."\n";
                        }
                }


        }
}


$tn = new telnet("192.168.255.100",23);
echo $tn->read_till("ogin: ");
$tn->write("admin\r\n");
echo $tn->read_till("word: ");
$tn->write("thieso\r\n");
echo $tn->read_till(":> ");
$tn->write("ps\r\n");
echo $tn->read_till(":> ");
echo $tn->close();
?>





----- Original Message -----
From: "Warren Vail" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Saturday, June 30, 2001 2:01 PM
Subject: RE: [PHP] Telnet and PHP


> By "active user input", I would assume that you mean every time the user
> makes a keystroke, the keystroke is sent to the host machine.  This is not
a
> characteristic of html which only sends information to the host machine
when
> some form of submit is clicked.  The advantage of the applet for this sort
> of thing is it runs on the browser client, and has the capability of
sending
> every keystroke directly to the host, bypassing the server side.
>
> On the server side, once the (PHP) application is done sending the
requested
> files to the web browser for one user, it moves on to handling the
requests
> for other users.  Can you imagine the load on a server if it had to reload
> your application every time, your user pressed a key.
>
> You never really made it clear where you expected this client to run,
> although PHP, at this point, can only run on the server.  Now if you are
> looking for something that your PHP code could use to 1. signon to a host
> somewhere, 2. execute some commands, 3. capture and process the results
and
> 4. disconnect before completing a single page to a web browser client (it
> will probably never do "active user input", because of the nature of PHP
and
> the web server), then I would suggest you consider "rexec", "rcp", "rsh"
or
> if what you want is in a file on the host machine, you could use the ftp
> functions.  These are not telnet, and do require special deamons running
on
> the host machine, but may do the trick.
>
> I have been looking for your telnet client for a long time as well, and if
> you find one, please remember to post it here, but I would suspect that
one
> of the problems in doing a telnet client in php is that the telnet client
> needs to be multi-threaded.  Perhaps someone will someday take open source
> like Dave's Telnet and fashion an extension to PHP.
>
> Til then, try the options above,
>
> Warren Vail
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, June 30, 2001 10:36 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Telnet and PHP
>
>
> I was doing some research on creating a webbased telnet client and I am
> unsatisfied with Java applets. I would like to create a server side telnet
> client, so the user side is only required to have a working web browser
that
> supports HTML.
>
> Thus, I turned to PHP. I found one example, but it does not allow for
active
> user input. While I will sit down this evening and work with the code, I
was
> wondering if anyone had/knew of a good example of a PHP telnet client.
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to