PHP code example of detain / sshwitch

1. Go to this page and download the library: Download detain/sshwitch 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 / sshwitch example snippets


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.";
}

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

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

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');