note 46369 deleted from function.fsockopen by danbrown
| From: | danbrown@php.net | Date: | Sun, 23 Jan 2011 16:54:15 +0000 |
| Subject: | note 46369 deleted from function.fsockopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176131@lists.php.net to get a copy of this message | ||
Note Submitter: elemental21 at hotmail dot com
----
Found this php class to use telnet from here:
http://cvs.adfinis.ch/cvs.php/phpStreamcast/telnet.class.php
There's no docs and a lot of it's in french though so maybe it will help
someone to have my working code. This code is used to telnet into a
pix and execute the "shun" command.
<?php
//-------telnet.class.php usage example---------
$telnet = new telnet;
// Next line is for logging.
//By default you need to create a folder called /log and give it the
//rights your webserver is running.
$telnet->setLog(1,"mylog");
$telnet->set_host("myhost.myplace.com");
//You need to set the prompt to what you know its going to be,
//then call wait_prompt...which waits for what you just set
$telnet->set_prompt("Password: ");
$telnet->connect();
$telnet->wait_prompt();
$telnet->write("mypassword");
//Have to change the prompt...in my example this is the
//prompt that a pix will change to after loggin in.
$telnet->set_prompt("pix> ");
$telnet->wait_prompt();
$telnet->write("en");
$telnet->set_prompt("Password: ");
$telnet->wait_prompt();
$telnet->write("enable_password");
//When you go into enable mode in a pix the prompt changes
$telnet->set_prompt("pix# ");
$telnet->wait_prompt();
$telnet->write("shun " . $shun_address);
$telnet->wait_prompt();
$telnet->write("clear xlate");
$telnet->wait_prompt();
$telnet->write("write mem");
$telnet->wait_prompt();
$telnet->write("exit");
$telnet->disconnect();
?>