Coder Social home page Coder Social logo

alvin-kiveu / mikrotik-routeros-api-php-sdk Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 274 KB

The repository is a software development kit (SDK) implemented in PHP for interacting with MikroTik RouterOS devices via their API.

License: MIT License

PHP 100.00%
mikrotik mikrotik-api mikrotik-hotspot mikrotik-routerboards routeros routeros-api routeros-client

mikrotik-routeros-api-php-sdk's Introduction

MIKROTIK - ROUTEROS - API - PHP - SDK

This PHP SDK provides a convenient interface for interacting with the Mikrotik RouterOS API. You can use this SDK to connect to a Mikrotik device, execute commands, and manage the RouterOS configuration.

Installation

This PHP SDK provides a convenient interface for interacting with the Mikrotik RouterOS API. You can use this SDK to connect to a Mikrotik device, execute commands, and manage the RouterOS configuration.

composer require ums/mikrotik

Usage

To use the SDK, create an instance of the MikrotikSdk class, and then use its methods to connect to a Mikrotik device.

use MikrotikSdk\MikrotikSdk;

$mikrotik = new MikrotikSdk;

// Connect to Mikrotik
$connect = $mikrotik->connect('192.168.88.1', 'admin', 'password');
if ($connect) {
    echo 'Connected';
} else {
    echo 'Not Connected';
}

Methods

connect($ip, $username, $password)

Connects to the Mikrotik device using the specified IP address, username, and password. Returns true on successful connection, otherwise false.

$connect = $mikrotik->connect('192.168.88.1', 'admin', 'password');

disconnect()

Disconnects from the Mikrotik device. Returns true on successful disconnection, otherwise false.

$disconnect = $mikrotik->disconnect();

Additional Methods

You can use the following methods to perform various operations on the Mikrotik device:

executeCommand($command, $param2 = true): Executes a RouterOS command. Returns true on success.

$result = $mikrotik->executeCommand('/interface/print');

sendCommand($com, $arr = array()): Sends a custom command with optional parameters. Returns the parsed response.

$response = $mikrotik->sendCommand('/ip/address/print', ['?interface' => 'ether1']);

parseResponse($response): Parses the raw response from RouterOS. Returns an array with parsed data.

$parsedData = $mikrotik->parseResponse($response);

Example

Here's a complete example demonstrating the usage of the SDK:

use MikrotikSdk\MikrotikSdk;

$mikrotik = new MikrotikSdk;

// Connect to Mikrotik
$connect = $mikrotik->connect('192.168.88.1', 'admin', 'password');
if ($connect) {
    // Execute a command
    $response = $mikrotik->sendCommand('/ip/address/print', ['?interface' => 'ether1']);
    
    // Parse and display the response
    $parsedData = $mikrotik->parseResponse($response);
    print_r($parsedData);

    // Disconnect from Mikrotik
    $mikrotik->disconnect();
} else {
    echo 'Not Connected';
}

The ip address, username, and password should be replaced with the actual values of your Mikrotik device.

License

The MIT License (MIT). Please see License File for more information.

Donate to this project

If you find this project useful, please consider making a donation. Any funds donated will be used to help further development on this project.

Donate

Credits

  • Nick Barnes

  • [Ben Menking](ben [at] infotechsc [dot] com)

  • Jeremy Jefferson

  • [Cristian Deluxe](djcristiandeluxe [at] gmail [dot] com)

  • [Mikhail Moskalev](mmv.rus [at] gmail [dot] com)

References



## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

## Donate to this project

If you find this project useful, please consider making a donation. Any funds donated will be used to help further development on this project.

[![Donate](https://img.shields.io/badge/Donate-PayStack-brightgreen)](https://paystack.com/pay/oqwdgv9xck)









mikrotik-routeros-api-php-sdk's People

Contributors

alvin-kiveu avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.