Пример #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;
Пример #2
0
 *
 * @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";
} catch (Exception $e) {