Пример #1
0
 *  limitations under the License.
 *
 * @category    Networking
 * @version     0.1 alpha
 * @author      Jesse Norell <*****@*****.**>
 * @copyright   2012 Jesse Norell <*****@*****.**>
 * @copyright   2012 Kentec Communications, Inc.
 * @license     http://www.apache.org/licenses/LICENSE-2.0 Apache License
 * @link        https://github.com/jnorell/Net_Telnet
 */
require_once "Net/Telnet.php";
try {
    // These settings worked with Allied Telesis cpe:
    $t = new Net_Telnet(array('host' => '10.20.30.40', 'login_prompt' => 'Login: '******'password_prompt' => 'Password: '******'login_success' => 'Login successful', 'login_fail' => 'Login failed', 'prompt' => '-->', 'debug' => false));
    echo $t->login(array('login' => 'manager', 'password' => 'friend'));
    // our terminal displays chars, so disable echo
    $t->echomode('none');
    while ($t->online() && ($s = fgets(STDIN)) !== false) {
        $t->println($s);
        if (($ret = $t->read_stream()) === false) {
            break;
        }
        echo $t->get_data();
    }
    $t->disconnect();
    // catch any buffered data
    echo $t->get_data();
} catch (Exception $e) {
    echo "Caught Exception ('{$e->getMessage()}')\n{$e}\n";
}
exit;