PHPackages                             detain/cisco\_parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. detain/cisco\_parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

detain/cisco\_parser
====================

Cisco IOS communications and configuration parsing library

v2.0.0(7y ago)67371LGPL-2.1-onlyPHPPHP &gt;=5.3.0CI failing

Since Jul 26Pushed 1w agoCompare

[ Source](https://github.com/detain/cisco_parser)[ Packagist](https://packagist.org/packages/detain/cisco_parser)[ RSS](/packages/detain-cisco-parser/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Cisco Parser
============

[](#cisco-parser)

Cisco IOS communications and configuration-parsing library for PHP. Provides:

- `Detain\CiscoParser\CiscoParser` — converts a Cisco IOS running/startup configuration text dump into a nested associative-array tree based on indentation depth.
- `Detain\CiscoParser\CiscoLoader` — SSH transport (via PECL `ssh2`) that drives an interactive shell against a real device and parses the output of common `show` commands (`show int status`, `show int `, `show log`, `show arp`, `show mac address-table`, `show ipv6 neighbors`, `show ipv6 routers`, DHCP snooping bindings, trunk ports, VLANs, err-disabled, …).

Build Status and Code Analysis
------------------------------

[](#build-status-and-code-analysis)

SiteStatus[![Travis-CI](https://camo.githubusercontent.com/2683be4a169ace8e2a3aa32a878fdc64086e28233c4406f193484c341a8c2882/687474703a2f2f692e69732e63632f73746f726167652f4759643735714e2e706e67 "Travis-CI")](https://camo.githubusercontent.com/2683be4a169ace8e2a3aa32a878fdc64086e28233c4406f193484c341a8c2882/687474703a2f2f692e69732e63632f73746f726167652f4759643735714e2e706e67)[![Build Status](https://camo.githubusercontent.com/0204dca9a99ae3b6bfc9912ee582f55ace40600362db25c9b444b5fe396eb556/68747470733a2f2f7472617669732d63692e6f72672f64657461696e2f636973636f5f7061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/detain/cisco_parser)[![CodeClimate](https://camo.githubusercontent.com/9758520860ea2cd9429ca0016fa3884afa1b24de4e33741ee1c0470c3ea60bf5/687474703a2f2f692e69732e63632f73746f726167652f47596c616765682e706e67 "CodeClimate")](https://camo.githubusercontent.com/9758520860ea2cd9429ca0016fa3884afa1b24de4e33741ee1c0470c3ea60bf5/687474703a2f2f692e69732e63632f73746f726167652f47596c616765682e706e67)[![Code Climate](https://camo.githubusercontent.com/3e1e15581026f4affde4b39a6e2086e1c9e7171dd4f55300cd29d2fc05b0d422/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f64657461696e2f636973636f5f7061727365722f6261646765732f6770612e737667)](https://codeclimate.com/github/detain/cisco_parser) [![Test Coverage](https://camo.githubusercontent.com/20632760bcc57666ddea8833beec2b758844bfe7358f8aef036679bb5ce26f0f/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f64657461696e2f636973636f5f7061727365722f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/detain/cisco_parser/coverage) [![Issue Count](https://camo.githubusercontent.com/ff15da8372d9bf489d9bfe6a9acc1b210225acf88510198f041015cfbed389ba/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f64657461696e2f636973636f5f7061727365722f6261646765732f69737375655f636f756e742e737667)](https://codeclimate.com/github/detain/cisco_parser)[![Scrutinizer](https://camo.githubusercontent.com/8e84cdad0130dc9d33badce3900914ca75fe3ac779d639659c4fb69e1c2b303d/687474703a2f2f692e69732e63632f73746f726167652f475965556e75782e706e67 "Scrutinizer")](https://camo.githubusercontent.com/8e84cdad0130dc9d33badce3900914ca75fe3ac779d639659c4fb69e1c2b303d/687474703a2f2f692e69732e63632f73746f726167652f475965556e75782e706e67)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1abf0f8e25ce3ca4f65a6bc9d26a16b406331a772c1d2b048740fc4cbcd01846/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64657461696e2f636973636f5f7061727365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/detain/cisco_parser/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/05c3617a6e3e4f55b7e1d98e558f7c6f7331840b98c1193bbf153ac7c77c8fe1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64657461696e2f636973636f5f7061727365722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/detain/cisco_parser/?branch=master) [![Build Status](https://camo.githubusercontent.com/f4ba8b88cef6eb9291322337d6335a52bbe250a403b0e0484136a4059c765da0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64657461696e2f636973636f5f7061727365722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/detain/cisco_parser/build-status/master)[![Codacy](https://camo.githubusercontent.com/2c5fa5cfbef7a395701fa9a8d912f65a41872a56dd358d7f2a99c5e60e993a64/687474703a2f2f692e69732e63632f73746f726167652f475969363643782e706e67 "Codacy")](https://camo.githubusercontent.com/2c5fa5cfbef7a395701fa9a8d912f65a41872a56dd358d7f2a99c5e60e993a64/687474703a2f2f692e69732e63632f73746f726167652f475969363643782e706e67)[![Codacy Badge](https://camo.githubusercontent.com/d05ea9ae6f85b66c60321ec10034eda9aabe052e3bf253e5bc008c3811b017a1/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3232363235316663303638663466643562346234656639613430303131643036)](https://www.codacy.com/app/detain/cisco_parser) [![Codacy Badge](https://camo.githubusercontent.com/6436b12c80cefe90081c4ad782ee6652a19fcee47fe213a623cda1e36fc3a90c/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f436f7665726167652f3235666137346562373463393437626639363936303266636665383765333439)](https://www.codacy.com/app/detain/cisco_parser?utm_source=github.com&utm_medium=referral&utm_content=detain/cisco_parser&utm_campaign=Badge_Coverage)[![Coveralls](https://camo.githubusercontent.com/a3c6188fec827d49dc58b5010e9dc949a917f2a42cfb6317034198bd73b3f15d/687474703a2f2f692e69732e63632f73746f726167652f47596a4e53696d2e706e67 "Coveralls")](https://camo.githubusercontent.com/a3c6188fec827d49dc58b5010e9dc949a917f2a42cfb6317034198bd73b3f15d/687474703a2f2f692e69732e63632f73746f726167652f47596a4e53696d2e706e67)[![Coverage Status](https://camo.githubusercontent.com/6dfb145429ea3a0d8361df74d8d29751e6fd14249d78cf82b2f3a434e5e5f2d3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f64657461696e2f64625f6162737472616374696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/detain/cisco_parser?branch=master)[![Packagist](https://camo.githubusercontent.com/38f9a31c2041ea45ca27d766fcc67af6afd8517836a04e1d112c22b27a3cc7f9/687474703a2f2f692e69732e63632f73746f726167652f475961634245582e706e67 "Packagist")](https://camo.githubusercontent.com/38f9a31c2041ea45ca27d766fcc67af6afd8517836a04e1d112c22b27a3cc7f9/687474703a2f2f692e69732e63632f73746f726167652f475961634245582e706e67)[![Latest Stable Version](https://camo.githubusercontent.com/4c5025de6579439294bd653197657fbc014efdb9db0f89f9e08f2fc9d4d2d0d2/68747470733a2f2f706f7365722e707567782e6f72672f64657461696e2f636973636f5f7061727365722f76657273696f6e)](https://packagist.org/packages/detain/cisco_parser) [![Total Downloads](https://camo.githubusercontent.com/bfc8305f5af87ec7fbb88b7a353aad72b1732717ce4f69ceefee6aa6ddb767ed/68747470733a2f2f706f7365722e707567782e6f72672f64657461696e2f636973636f5f7061727365722f646f776e6c6f616473)](https://packagist.org/packages/detain/cisco_parser) [![Latest Unstable Version](https://camo.githubusercontent.com/8c5c051f556da2bbbf4cc41eb224dcca6b3ad913dd953f3fcfba7269f3396b7f/68747470733a2f2f706f7365722e707567782e6f72672f64657461696e2f636973636f5f7061727365722f762f756e737461626c65)](//packagist.org/packages/detain/cisco_parser) [![Monthly Downloads](https://camo.githubusercontent.com/716ebaa170c2e57a00f47b21e5d1766baaedcdba30cf92616c0f0434f2647fcf/68747470733a2f2f706f7365722e707567782e6f72672f64657461696e2f636973636f5f7061727365722f642f6d6f6e74686c79)](https://packagist.org/packages/detain/cisco_parser) [![Daily Downloads](https://camo.githubusercontent.com/2d146f838bca3aa6f59ae6cb6509d7c6656973d908352a3ca54dcfb31c5b11dd/68747470733a2f2f706f7365722e707567782e6f72672f64657461696e2f636973636f5f7061727365722f642f6461696c79)](https://packagist.org/packages/detain/cisco_parser) [![License](https://camo.githubusercontent.com/d6239539fcf2f415c82b4f7ecf9b755d34f699b3ade09cd4885115038e5646a7/68747470733a2f2f706f7365722e707567782e6f72672f64657461696e2f636973636f5f7061727365722f6c6963656e7365)](https://packagist.org/packages/detain/cisco_parser)Requirements
------------

[](#requirements)

- PHP **7.4** or newer
- `ext-mbstring`
- `ext-ssh2` — **only** required if you use `CiscoLoader` to talk to a real device. The pure-text `CiscoParser` works without it.

Installation
------------

[](#installation)

Install with Composer:

```
composer require detain/cisco_parser
```

Usage
-----

[](#usage)

### Parsing a configuration

[](#parsing-a-configuration)

`CiscoParser::parse_cisco_children()` takes an array of lines (typically from `explode("\n", file_get_contents(...))` after stripping `\r`) and produces a nested tree where each node has:

- `command` — the first whitespace-delimited token on the line
- `arguments` — (optional) anything after the first token
- `children` — (optional) the sub-block of more deeply-indented lines

```
use Detain\CiscoParser\CiscoParser;

$config =  hostname
            [arguments] => Switch1
        )
    [1] => Array
        (
            [command] => interface
            [arguments] => FastEthernet0/1
            [children] => Array
                (
                    [0] => Array
                        (
                            [command] => switchport
                            [arguments] => access vlan 10
                        )
                    [1] => Array
                        (
                            [command] => spanning-tree
                            [arguments] => portfast
                        )
                )
        )
    [2] => Array
        (
            [command] => interface
            [arguments] => FastEthernet0/2
            [children] => Array
                (
                    [0] => Array
                        (
                            [command] => description
                            [arguments] => Uplink
                        )
                )
        )
)

```

### Parsing from the command line

[](#parsing-from-the-command-line)

A small wrapper script is shipped at `bin/cisco_parser.php`:

```
php bin/cisco_parser.php /path/to/show-running-config.txt
```

If installed via Composer, the same script is exposed at `vendor/bin/cisco_parser.php`.

The wrapper recognises an optional `Building configuration...` / `Current configuration : N bytes` header (as emitted by `show running-config`) and pulls the byte count out into the result. Files without that header are parsed in full.

### Talking to a real device

[](#talking-to-a-real-device)

`CiscoLoader` opens an SSH session and exposes typed helpers around the most common `show` commands. It requires the `ssh2` PECL extension.

```
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();              // requires enable mode (#)
$device->show_int('Gi1/0/1');
$device->trunk_ports();
$device->vlans();
$device->errdisabled();
$device->dhcpsnoop_bindings();
$device->mac_address_table();
$device->arp_table();
$device->ipv6_neighbor_table();
$device->ipv6_routers();

// Push configuration. Requires enable mode (#).
$device->configure("interface Gi1/0/2\n description new label\n");
$device->write_config();          // saves running-config to startup-config

$device->disconnect();
```

`CiscoLoader::exec($cmd)` is available for any other command not covered by a helper; it returns the device's raw response with the trailing prompt stripped.

Testing
-------

[](#testing)

```
composer install
composer test
```

For coverage output:

```
composer test-coverage
# → tests/ + coverage.xml (clover format)
```

License
-------

[](#license)

The Cisco Parser library is licensed under the [LGPL-2.1-only](https://opensource.org/licenses/LGPL-2.1) license.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance64

Regular maintenance activity

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 98.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~162 days

Total

4

Last Release

2730d ago

Major Versions

v1.0.2 → v2.0.02018-11-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1036e0717211b8030b83cbe729e8ba6ba442fdbd5285fb97a39d7dcfe339342?d=identicon)[detain](/maintainers/detain)

---

Top Contributors

[![detain](https://avatars.githubusercontent.com/u/1364504?v=4)](https://github.com/detain "detain (89 commits)")[![mend-bolt-for-github[bot]](https://avatars.githubusercontent.com/in/16809?v=4)](https://github.com/mend-bolt-for-github[bot] "mend-bolt-for-github[bot] (1 commits)")

---

Tags

automationcatalystciscocisco-iosconfiguration-parseriosios-xenetconfnetworknetwork-automationnetwork-configurationnetwork-devicenetwork-monitoringnetwork-programmabilityparserphpphp-libraryrouterswitchroutersshnetworkswitchiostelnetcisco

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/detain-cisco-parser/health.svg)

```
[![Health](https://phpackages.com/badges/detain-cisco-parser/health.svg)](https://phpackages.com/packages/detain-cisco-parser)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[mck89/peast

Peast is PHP library that generates AST for JavaScript code

18834.7M29](/packages/mck89-peast)[ivopetkov/html5-dom-document-php

HTML5 DOMDocument PHP library (extends DOMDocument)

6031.4M49](/packages/ivopetkov-html5-dom-document-php)[ergebnis/json

Provides a Json value object for representing a valid JSON string.

2421.7M8](/packages/ergebnis-json)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
