PHPackages                             detain/sshwitch - 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. detain/sshwitch

ActiveLibrary

detain/sshwitch
===============

Login and run commands on your network devices via an ssh connection on a remote server. Easy to use PHP static class methods with static chaining support for rapid development. Supports Cisco and Juniper network routers and switches with more easily added.

v1.0.0(1y ago)138↓100%GPL-3.0PHP

Since Nov 6Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/detain/sshwitch)[ Packagist](https://packagist.org/packages/detain/sshwitch)[ RSS](/packages/detain-sshwitch/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

sshwitch SSH Switch
===================

[](#sshwitch-ssh-switch)

Login and run commands on your network devices via an ssh connection on a remote server. Easy to use PHP static class methods with static chaining support for rapid development. Supports Cisco and Juniper network routers and switches with more easily added.

We handle the switch login and elevation using [rancid](https://www.shrubbery.net/rancid/) and it supports more than what I've adde so far. It would take only a few lines of code to add support to login to devices from Extreme Networks, Juniper, Procket Networks, Redback, A10, Alteon, Avocent (Cyclades), Bay Networks (Nortel), ADC-kentrox, Foundry, HP, Hitachi, Juniper Networks, MRV, Mikrotik, Netscreen, Nokia (Alcatel-Lucent), Netscaler, Riverstone, Netopia, Xirrus, and Arrcus.

Requirements
------------

[](#requirements)

- PHP 7.4 or later
- `ssh2` PHP extension
- RANCID's `clogin` script for certain network commands (e.g., Cisco devices)

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

[](#installation)

You can install SSHwitch via Composer:

```
composer require detain/sshwitch
```

Usage
-----

[](#usage)

### Connecting and Executing Commands

[](#connecting-and-executing-commands)

```
use Detain\Sshwitch\Sshwitch;

// Set up SSHwitch with a switch and commands
$switch = '10.0.0.1'; // IP address or hostname of the switch
$commands = [
    'show version',
    'show ip interface brief'
];

// Run commands on the switch
$result = Sshwitch::run($switch, $commands);

// Check the output
if ($result !== false) {
    echo "Commands executed successfully. Output:\n";
    print_r($result);
} else {
    echo "Failed to execute commands.";
}
```

### Getting and Setting Properties

[](#getting-and-setting-properties)

SSHwitch uses magic methods for getting and setting static properties.

```
// Set autoDisconnect to false
Sshwitch::setAutoDisconnect(false);

// Check if chaining mode is enabled
$chaining = Sshwitch::getChaining();
echo "Chaining mode is " . ($chaining ? 'enabled' : 'disabled');
```

Configuration
-------------

[](#configuration)

The following constants are required for SSHwitch to connect to the switch:

- `CLOGIN_SSH_HOST` - The SSH host address of the device.
- `CLOGIN_SSH_PORT` - The SSH port to use for the connection.
- `CLOGIN_SSH_USER` - The username for SSH login.
- `CLOGIN_SSH_KEY` - The file path to the SSH private key.

### Example Config

[](#example-config)

```
define('CLOGIN_SSH_HOST', '10.0.0.1');
define('CLOGIN_SSH_PORT', 22);
define('CLOGIN_SSH_USER', 'sshuser');
define('CLOGIN_SSH_KEY', '/path/to/private_key');
```

Methods
-------

[](#methods)

### `connect()`

[](#connect)

Connects to the SSH server if not already connected.

### `disconnect()`

[](#disconnect)

Disconnects the current SSH connection.

### `run($switch, $commands, $type = 'cisco')`

[](#runswitch-commands-type--cisco)

Runs commands on the specified switch and returns the output.

### Magic Methods

[](#magic-methods)

- `get()` and `set()` for getting and setting public static properties.

License
-------

[](#license)

This project is licensed under the GNU GPL v3 license.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance68

Regular maintenance activity

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 88.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

Unknown

Total

1

Last Release

550d ago

### 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 (8 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

ciscoextremehpjunipermikrotiknetscalernetworkingphprancidrouterssshswitches

### Embed Badge

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

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

PHPackages © 2026

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