PHP code example of epiecs / phpmiko

1. Go to this page and download the library: Download epiecs/phpmiko 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/ */

    

epiecs / phpmiko example snippets




ce = new \Epiecs\PhpMiko\ConnectionHandler([
	'device_type' => 'junos',
	'hostname'    => '192.168.0.1',
	'username'    => 'my_user',
	'password'    => 'mysafepassword',
]);

print_r($device->operation([
	'show system uptime',
	'show system alarms',
]));

/*
Array
(
    [show system uptime] => fpc0:
--------------------------------------------------------------------------
Current time: 2018-11-02 02:30:18 CET
Time Source:  LOCAL CLOCK 
System booted: 2018-09-15 09:22:02 CEST (6w5d 18:08 ago)
Protocols started: 2018-09-15 09:24:40 CEST (6w5d 18:05 ago)
Last configured: 2018-10-14 06:47:11 CEST (2w4d 20:43 ago) by itdept
 2:30AM  up 47 days, 18:08, 3 users, load averages: 0.11, 0.11, 0.08

    [show system alarms] => No alarms currently active
)
*/

print_r($device->configure([
	'set interfaces ge-0/0/47 description "Test for documentation"',
	'edit interfaces ge-0/0/46',
	'set description "Sequential commands work"',
]));

/*
Array
(
    [set interfaces ge-0/0/47 description "Test for documentation"] => 
    [edit interfaces ge-0/0/46] => 
    [set description "Sequential commands work"] => 
)
*/



ce = new \Epiecs\PhpMiko\ConnectionHandler([
	'device_type' => 'junos',
	'hostname'    => '192.168.0.1',
	'username'    => 'username',
	'password'    => 'password',
	'protocol'    => 'ssh',          //default is ssh
	'port'        => 22,             //defaults to the protocol default if not set
	'secret'      => 'secret',       //default is ''
	'verbose'     => false,          //default is false
	'raw'         => false           //default is false
]);

print_r($device->operation('show interfaces ge-0/0/0'));

print_r($device->operation([
	'show interfaces ge-0/0/0',
]));

print_r($device->operation([
	'show interfaces ge-0/0/0',
	'show interfaces ge-0/0/1',
]));

print_r($device->cli([
	'pwd',
	'cd /var/www ; pwd ; ls -l'
]));

print_r($device->operation([
	'show interfaces terse',
	'show configuration interfaces ge-0/0/0'
]));

print_r($device->configure([
	'set interfaces ge-0/0/0 description "Test for documentation"',
	'edit interfaces ge-0/0/1',
	'set description "Sequential commands work"',
]));

$device->raw();
$device->raw(false);

$device->disconnect();
plaintext
--- output cut short for brevity, notice the arrows

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0013, network: 0.0002s)
00000000  00:00:00:00:00:00:00:05:64:61:74:65:0a           ........date.

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.1556, network: 0.0011s)
00000000  00:00:00:02:00:00:00:07:64:61:74:65:0d:0d:0a     ........date...

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.1458, network: 0.0001s)
00000000  00:00:00:02:00:00:00:1f:46:72:69:20:4a:75:6e:20  ........Fri Jun
00000010  32:31:20:31:31:3a:31:36:3a:31:32:20:43:45:53:54  21 11:16:12 CEST
00000020  20:32:30:31:39:0d:0a                              2019..