PHP code example of detain / cisco_parser

1. Go to this page and download the library: Download detain/cisco_parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

detain / cisco_parser example snippets


use Detain\CiscoParser\CiscoParser;

$config = <<<CFG
hostname Switch1
interface FastEthernet0/1
 switchport access vlan 10
 spanning-tree portfast
interface FastEthernet0/2
 description Uplink
CFG;

$lines  = explode("\n", str_replace("\r", '', $config));
$parser = new CiscoParser();
$tree   = $parser->parse_cisco_children($lines);

print_r($tree);

use Detain\CiscoParser\CiscoLoader;

$device = new CiscoLoader('switch1.example.net', 'admin', 's3cret');

// Implicit connect on first exec() because $autoconnect is true by default.
$status = $device->show_int_status();
foreach ($status as $port) {
    echo "{$port['interface']}\t{$port['status']}\t{$port['vlan']}\n";
}

// Other helpers
$device->show_log();              //          // saves running-config to startup-config

$device->disconnect();
sh
php bin/cisco_parser.php /path/to/show-running-config.txt