Esempio n. 1
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;
Esempio n. 2
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;
Esempio n. 3
0
 * @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";
} catch (Exception $e) {
    echo "Caught Exception ('{$e->getMessage()}')\n{$e}\n";
}
exit;