imafaz/mikrolink

lightweight library for manage mikrotik router os with api

1.0.1 2024-11-06 08:31 UTC

This package is auto-updated.

Last update: 2025-01-06 08:52:49 UTC


README

MikroLink is a lightweight PHP library designed for interacting with MikroTik routers using their API. This library simplifies the process of managing and automating tasks on MikroTik devices programmatically.

Requirements

To utilize this library effectively, ensure your environment meets the following requirements:

  • PHP version 7.0 or higher

Installation

For seamless installation, use Composer:

composer require imafaz/mikrolink

Quick Start

Once the library is installed, include it in your PHP script:

require_once 'vendor/autoload.php';

use MikrotikApi\MikroLink;

Usage

Initialize the MikroLink object with debug mode, timeout, attempts, and delay settings:

$router = new MikroLink;

Connect to a MikroTik router using its IP, username, password, port, and optional SSL mode:

$router->connect('192.168.1.1', 'admin', 'password', 8728, false);

Execute commands on the connected router:

$response = $router->exec('/interface/print');

var_dump($response); //print array response

disconnect router connection :

$router->disconnect();

Available Methods

__construct

Description:

Initializes the MikroLink object with debugging and connection settings.

Signature:

$router = new MikroLink( int $timeout = 1,  int $attempts = 3,int  $delay = 0,$logFile = 'mikrolink.log',$printLog = false);

Attributes:

connect

Description:

Connects to a MikroTik router using the provided credentials and connection details.

Signature:

$router->connect(string $ip, string $username, string $password, int $port, $ssl = false);

Attributes:

exec

Description:

Executes a MikroTik API command with optional parameters.

Signature:

$router->exec(string $command, array $params = null);

Attributes:

disconnect

Description:

Terminates the connection with the MikroTik router.

Signature:

$router->disconnect();

License

This library is licensed under the MIT License