PHP code example of marbocub / network-equipment
1. Go to this page and download the library: Download marbocub/network-equipment 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/ */
marbocub / network-equipment example snippets
Marbocub\NetworkEquipment\TelnetClient;
use Graze\TelnetClient\Exception\TelnetException;
$telnet = TelnetClient::factory();
try {
$telnet->connect("127.0.0.1:23");
$telnet->login("username", "password");
$telnet->execute("terminal length 0");
$response = $telnet->execute("show interface status");
echo $response;
print_r($response->getResponseArray());
} catch (TelnetException $e) {
echo $e->getMessage();
die();
}
Marbocub\NetworkEquipment\ResponseParser;
/* executed command and the response */
$command = "show int status";
$response = $yourSSHClient->execute($command);
echo $response;
/* start parse */
$parser = new ResponseParser();
$result = $parser->parse($command, $response);
print_r($result);
use Marbocub\NetworkEquipment\TelnetClient;
use Graze\TelnetClient\Exception\TelnetException;
$telnet = TelnetClient::factory();
try {
$telnet->connect("127.0.0.1:23");
$telnet->login("username", "password");
} catch (TelnetException $e) {
/* failed */
}
try {
$telnet->execute("terminal length 0");
$response = $telnet->execute("show interface status");
// Getting the response text
echo $response;
// Getting the parsed array
print_r($response->getResponseArray());
} catch (TelnetException $e) {
/* failed */
}
try {
$telnet->enable("password");
} catch (TelnetException $e) {
/* failed */
}
$commands = [
'interface Gi1/0/1',
'switchport access vlan 100',
];
try {
$telnet->configure($commands);
} catch (TelnetException $e) {
/* failed */
}
$telnet->connect("127.0.0.1:23', TelnetClient::PROMPT_JUNOS);
$telnet->connect("127.0.0.1:23', TelnetClient::PROMPT_SHELL);
use Marbocub\NetworkEquipment\ResponseParser;
$parser = new ResponseParser();
$result = $parser->parse(
"executed command",
"response text"
);