Skip to content

meklis/console-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Console-Client

PHP library for login/password connections to devices over Telnet and SSH.

Install

composer require meklis/console-client

Example

SSH connection to ZTE devices

require __DIR__ . '/vendor/autoload.php';

$ssh = new \Meklis\Network\Console\SSH();
$ssh->setDeviceHelper(new \Meklis\Network\Console\Helpers\ZTE());
$ssh->connect("10.0.0.2", 2222); //Ip and custom port 
$ssh->login("login", "password"); 
echo $ssh->exec("show card");

Telnet connection to Dlink device

require __DIR__ . '/vendor/autoload.php';

$ssh = new \Meklis\Network\Console\Telnet();
$ssh->setDeviceHelper(new \Meklis\Network\Console\Helpers\Dlink());
$ssh->connect("10.0.0.1");
$ssh->login("login", "password");
echo $ssh->exec("show switch");

Supported vendors

  • Alcatel
  • Alaxala
  • Bdcom
  • Cdata
  • Dlink
  • Dell
  • Edgecore
  • Foxgate
  • Gcom
  • Huawei
  • Tp-link
  • Ios
  • ZTE
  • Junos
  • Linux
  • Vsolution
  • Xos

For adding own vendors you can create Helper extended from DefaultHelper and implement HelperInterface.

Example of helper

namespace Meklis\Network\Console\Helpers;

class Cdata extends DefaultHelper
{
    protected $prompt = 'OLT(.*?)[>#]';
    protected $userPrompt = 'ame:';
    protected $passwordPrompt = 'ord:';
    protected $afterLoginCommands = [];
    protected $beforeLogoutCommands = [];
    protected $windowSize = null;

    public function isDoubleLoginPrompt(): bool
    {
        if ($this->connectionType === 'ssh') {
            return true;
        }
        return $this->doubleLoginPrompt;
    }
}