Beispiel #1
0
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  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";
Beispiel #2
0
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  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";
$www = "www.google.com";
$debug = false;
try {
    $t = new Net_Telnet(array('debug' => $debug, 'telnet' => false));
    $t->connect(array('host' => $www, 'port' => 80));
    $t->println("GET / HTTP/1.1\nHost: {$www}\n\n");
    $t->read_stream();
    echo $t->get_data();
    $t->disconnect();
} catch (Exception $e) {
    echo "Caught Exception ('{$e->getMessage()}')\n{$e}\n";
}
exit;
Beispiel #3
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";
# Note this is used as both a hostname and as part of the command prompt
# (which works for our configuration, but check your own)
$cmts = 'arris-cmts';
try {
    $t = new Net_Telnet(array('host' => $cmts, 'debug' => false, 'telnet_bugs' => false));
    echo $t->login(array('login_prompt' => 'Login: '******'login_success' => "[{$cmts}]", 'login_fail' => 'Login failed', 'password_prompt' => 'Password: '******'prompt' => ' remote1> ', 'login' => 'root', 'password' => ''));
    $t->page_prompt('Type: <space> to page; <return> advance 1 line; Q to quit ', ' ');
    if ($t->send("manage\r") && $t->expect(" box#", "show\r") && $t->expect(" box#", "info\r") && $t->expect(" box#", "admin\r") && $t->expect(" admin#", "show\r") && $t->expect(" admin#", "info\r") && $t->expect(" admin#", "exit\r")) {
        $t->read_stream();
        echo $t->get_data();
    } else {
        echo "ERROR looking up system information\n\n";
    }
    // Arris CMTS 1000 changes how it handles line endings in BINARY mode,
    // so just disable BINARY:
    $t->send_telcmd(TEL_DONT, TELOPT_BINARY);
    $t->send_telcmd(TEL_WONT, TELOPT_BINARY);
    // our terminal will print chars on screen, disable echo
    $t->echomode('none');
    while ($t->online() && ($s = fgets(STDIN)) !== false) {
Beispiel #4
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";
$router = 'router1';
$password = '******';
$enable_secret = 'evenmoreso';
try {
    $t = new Net_Telnet($router);
    $t->connect();
    echo $t->login(array('login_prompt' => '', 'login_success' => '', 'login_fail' => '% Access denied', 'login' => '', 'password' => $password, 'prompt' => "{$router}>"));
    // Cisco page prompt
    $t->page_prompt("\n --More-- ", " ");
    echo $t->cmd('show version');
    echo $t->cmd('traceroute github.com');
    # send enable command
    $t->println("enable");
    # reuse login() to send enable secret
    echo $t->login(array('login_success' => '', 'password' => $enable_secret, 'prompt' => "{$router}#"));
    echo $t->cmd('show running-config');
    $t->disconnect();
    // catch any buffered data
    echo $t->get_data();
    echo "\n";