PHPackages                             ocolin/routeros - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ocolin/routeros

ActiveLibrary[API Development](/categories/api)

ocolin/routeros
===============

Client for RouterOS API

v0.5.1(1mo ago)04↑900%MITPHPPHP ^8.4

Since Apr 22Pushed 1mo agoCompare

[ Source](https://github.com/ocolin/RouterOS)[ Packagist](https://packagist.org/packages/ocolin/routeros)[ Docs](https://github.com/ocolin/routeros)[ RSS](/packages/ocolin-routeros/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (5)Versions (8)Used By (0)

[![Packagist Version](https://camo.githubusercontent.com/60db9ea294314b7bf5d4965b509b006f6556e14796b376b36015dd47ca4fa993/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f636f6c696e2f726f757465726f73)](https://camo.githubusercontent.com/60db9ea294314b7bf5d4965b509b006f6556e14796b376b36015dd47ca4fa993/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f636f6c696e2f726f757465726f73)[![PHP Version](https://camo.githubusercontent.com/f3e52b135cf0baa689d4b8c69ba74a67a0bbd5aef049f4761e0e70d2184e6dcb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6f636f6c696e2f726f757465726f732f706870)](https://camo.githubusercontent.com/f3e52b135cf0baa689d4b8c69ba74a67a0bbd5aef049f4761e0e70d2184e6dcb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6f636f6c696e2f726f757465726f732f706870)[![License](https://camo.githubusercontent.com/e77c77f8028ff345c283d453c9caee56bdb74b53bb15cfb3d2b120bcf7bc5fc0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6f636f6c696e2f726f757465726f73)](https://camo.githubusercontent.com/e77c77f8028ff345c283d453c9caee56bdb74b53bb15cfb3d2b120bcf7bc5fc0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6f636f6c696e2f726f757465726f73)[![Downloads](https://camo.githubusercontent.com/9791b3ca412d640d1fe1795f68fb0d3d2c082d72117f0edcf15dc451d26b7b95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f636f6c696e2f726f757465726f73)](https://camo.githubusercontent.com/9791b3ca412d640d1fe1795f68fb0d3d2c082d72117f0edcf15dc451d26b7b95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f636f6c696e2f726f757465726f73)

RouterOS
========

[](#routeros)

A PHP 8.4 client for the MikroTik RouterOS API.

This library provides a clean, modern interface for communicating with MikroTik RouterOS devices via their API protocol. Built with a layered architecture, it handles the low-level binary protocol details so you can focus on managing your network infrastructure. Features include a fluent query builder, SSL support, environment variable configuration, and a comprehensive test suite.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
    - [Parameters](#parameters)
    - [Using an Array](#using-an-array)
    - [Using a Config Object](#using-a-config-object)
    - [Environment Variables](#environment-variables)
- [Basic Usage](#basic-usage)
    - [String input](#string-input)
    - [Array input](#array-input)
    - [Command Object Input](#command-object-input)
- [Query Builder](#query-builder)
    - [Attribute](#attribute)
    - [Query](#query)
    - [Logical Operators](#logical-operators)
    - [Proplist](#proplist)
    - [Tags](#tags)
    - [Aliases](#Aliases)
- [Streaming](#streaming)
- [SSL](#ssl)
- [Laravel Integration](#laravel-integration)
    - [Laravel Installation](#laravel-installation)
    - [Laravel Configuration](#Laravel-configuration)
    - [Laravel Usage](#Laravel-usage)
- [Migrating from routeros-api-php](#migrating-from-routeros-api-php)
- [Roadmap](#roadmap)
- [License](#license)

---

Requirements
------------

[](#requirements)

- PHP 8.4 or higher
- MikroTik RouterOS device with API service enabled

---

Installation
------------

[](#installation)

```
composer require ocolin/routeros
```

---

Quick Start
-----------

[](#quick-start)

```
use Ocolin\RouterOS\Client;

$client = new Client([
    'host'     => '192.168.88.1',
    'username' => 'admin',
    'password' => 'secret'
]);

$interfaces = $client->query( '/interface/print' );

foreach( $interfaces as $interface ) {
    echo $interface['name'] . "\n";
}
```

---

Configuration
-------------

[](#configuration)

The client can be configured by passing an associative array, a `Config` object, or any object whose properties match the configuration parameters. The array approach is the most common and concise.

### Parameters

[](#parameters)

ParameterTypeDefaultENV VariableDescriptionhoststringrequired`ROUTEROS_HOST`IP address or hostname of deviceusernamestring`admin``ROUTEROS_USERNAME`Username to authenticate withpasswordstring`''``ROUTEROS_PASSWORD`Password to authenticate withsslbool`false``ROUTEROS_SSL`Enable SSL connectionportint`8728``ROUTEROS_PORT`Port for non-SSL connectionssslPortint`8729``ROUTEROS_SSL_PORT`Port for SSL connectionstimeoutint`10``ROUTEROS_TIMEOUT`Connection timeout in secondssocketTimeoutint`30``ROUTEROS_SOCKET_TIMEOUT`Response timeout in secondssslVerifybool`false``ROUTEROS_SSL_VERIFY`Verify SSL certificate### Using an Array

[](#using-an-array)

```
$client = new Client([
    'host'     => '192.168.88.1',
    'username' => 'admin',
    'password' => 'secret'
]);
```

### Using a Config Object

[](#using-a-config-object)

```
$config = new Config([
    'host' => '192.168.88.1',
]);

$client = new Client( $config );
```

### Environment Variables

[](#environment-variables)

Environment variables can be used instead of passing configuration directly. The ENV variable names are listed in the parameters table above.

```
// .env file
ROUTEROS_HOST=192.168.88.1
ROUTEROS_USERNAME=admin
ROUTEROS_PASSWORD=secret
```

#### Prefix Support

[](#prefix-support)

To support multiple devices, an optional prefix can be used:

```
// .env file
ROUTEROS_CORE_HOST=10.0.0.1
ROUTEROS_EDGE_HOST=10.0.0.2
```

```
$core = new Client( envPrefix: 'CORE' );
$edge = new Client( envPrefix: 'EDGE' );
```

---

Basic Usage
-----------

[](#basic-usage)

There are three methods that can be used for inputting data to a device. A simple string command, an array of command words, or a `Command` object which provides methods for more complex queries.

### String input

[](#string-input)

This is good for simple single command queries that don't require any special conditions.

#### Example

[](#example)

```
$interfaces = $client->query( command: '/interface/print' );

foreach( $interfaces as $interface )
{
    echo $interface['name'] . PHP_EOL;
}
```

### Array input

[](#array-input)

Useful for advanced users who prefer working directly with the API syntax, or for sending commands not yet supported by the Command builder.

#### Example

[](#example-1)

```
$interfaces = $client->query( command: [
    '/interface/print',
    '=disabled=no',
    '?type=ether'
]);
foreach( $interfaces as $interface )
{
    echo $interface['name'] . PHP_EOL;
}
```

### Command Object Input

[](#command-object-input)

A `Command` object is included for making complex queries easier to type doesn't require that you know the API syntax.

#### Example

[](#example-2)

```
use Ocolin\RouterOS\Command;

$interfaces = $client->query(
    command: new Command('/interface/print')
        ->attribute( key: 'disabled', value: false )
        ->query( 'type' )->equals( 'ether' )
);
foreach( $interfaces as $interface )
{
    echo $interface['name'] . PHP_EOL;
}
```

---

Query Builder
-------------

[](#query-builder)

The `Command` class allows you to create complex queries with a simple syntax. The `Query` takes one argument for the constructor, which is the RouterOS command word.

```
$command = new Command( '/interface/print' );
```

In this example we are sending a simple command with no other parameters. The command word is always required by RouterOS.

### Attribute

[](#attribute)

The attribute method allows you to specify attributes to your query. This is useful when creating and modifying an object on the Mikrotik device. Each attribute has a name and a value. RouterOS uses "yes" and "no" for boolean attributes, but this client will automatically convert boolean for you.

```
$command = new Command( '/interface/print' )
    ->attribute( key: 'disabled', value: true );
```

### Query

[](#query)

The query method allows you to filter the results of your query.

#### Query Arguments

[](#query-arguments)

One way to add a query is by just using the constructor arguments. This is a means to manually enter the data without any helped functions.

```
// Get interfaces of type equal to ether
$command = new Command( '/interface/print' )
    ->query( key: 'type', value: 'ether', operator: '=' );
```

```
// Get interfaces with any link-downs
$command = new Command( '/interface/print' )
    ->query( key: 'link-downs', value: 0, operator: '>' );
```

#### Equals

[](#equals)

This function takes a single value and which the key value must be equal to.

```
// Get interfaces of type equal to ether
$command = new Command( '/interface/print' )
    ->query( key: 'type' )->equals( 'ether' );
```

#### lessThan

[](#lessthan)

This function takes a single value which the key value must be less than.

```
// Get interfaces with any no link-downs
$command = new Command( '/interface/print' )
    ->query( key: 'link-downs' )->lessThan( 1 );
```

#### greaterThan

[](#greaterthan)

This function takes a single value which the key value must be greater than.

```
// Get interfaces with link-downs
$command = new Command( '/interface/print' )
    ->query( key: 'link-downs' )->greaterThan( 0 );
```

#### exists

[](#exists)

Include if a property exists for the return results.

```
// Get interfaces with link-downs property
$command = new Command( '/interface/print' )
    ->query( key: 'link-downs' )->exists();
```

#### notExists

[](#notexists)

Include if a property does not exist.

```
// Get interfaces without link-downs property
$command = new Command( '/interface/print' )
    ->query( key: 'link-downs' )->notExists();
```

### Logical Operators

[](#logical-operators)

When using multiple queries, you can specify a logical operator to indicate if all the queries should be met, or if any should be met, or it they should not be met.

The logical operator must always come after your query parameters for RouterOS to understand it.

#### And Operator

[](#and-operator)

The `and` operator requires that all query parameters must be met. This is also the default operator so does not need to be specified.

```
// Get interfaces of type equal to ether AND has link-downs
$command = new Command( '/interface/print' )
    ->query( key: 'type' )->equals( 'ether' )
    ->query( key: 'link-downs' )->greaterThan( 0 )
    ->and();
```

#### Or Operator

[](#or-operator)

The `or` operator requires any of the query parameters to be met.

```
// Get interfaces of type equal to ether OR has link-downs
$command = new Command( '/interface/print' )
    ->query( key: 'type' )->equals( 'ether' )
    ->query( key: 'link-downs' )->greaterThan( 0 )
    ->or();
```

#### Not Operator

[](#not-operator)

This operator says to filter results to not contain the previous query parameter. Unlike AND and OR, this operator can be used prior to the end and can be specified for each query paramater.

```
// Get interfaces of type not a vlan
$command = new Command( '/interface/print' )
    ->query( key: 'type' )->equals( 'vlan' )
    ->not();
```

### Proplist

[](#proplist)

The `proplist` allows you to limit the columns that are returned in your results.

```
$command = new Command( '/interface/print' )->proplist(['name', 'type']);
```

### Tags

[](#tags)

Tag IDs can be added to queries.

```
$command = new Command( '/interface/print' )->tag( 123 );
```

```
$command = new Command( '/interface/print' )->tag( 'abc' );
```

### Aliases

[](#aliases)

There are a few alias functions which exist for those using method names found in other libraries.

#### Where

[](#where)

The where method is an alias for the `query` method.

```
// Get interfaces without link-downs property
$command = new Command( '/interface/print' )
    ->where( key: 'link-downs' )->notExists();
```

#### Equal

[](#equal)

The equal method is an alias for the attribute method.

```
$command = new Command( '/interface/print' )
    ->equal( key: 'disabled', value: true );
```

##### Operations

[](#operations)

The operations method is an alias for the logical operator methods, using the same syntax as routeros-api-php.

```
$command = new Command( '/interface/print' )
    ->query( 'type' )->equals( 'ether' )
    ->query( 'type' )->equals( 'vlan' )
    ->operations( '|' );
```

---

Streaming
---------

[](#streaming)

Some RouterOS commands return a continuous stream of data rather than a single response. The most common example is the `/interface/listen` command which sends updates whenever an interface changes state. The `stream()` method handles these commands by returning a Generator that yields results one at a time as they arrive.

Unlike `query()` which collects all results and returns them as an array, `stream()` never stops on its own — it will keep yielding results until you break out of the loop or the connection is closed.

```
foreach( $client->stream( '/interface/listen' ) as $update ) {
    echo $update['name'] . ' changed state' . PHP_EOL;

    // Stop listening after first update
    if( $someCondition ) {
        break;
    }
}
```

The `stream()` method accepts the same input types as `query()` — a string command, an array of words, or a `Command` object.

> **Note:** To gracefully stop a streaming command, break out of the loop. Explicit command cancellation using `/cancel` will be available in a future release when concurrent command support is added.

---

SSL
---

[](#ssl)

The client supports SSL connections using RouterOS's secure API service. SSL is disabled by default and must be enabled in your configuration.

### RouterOS Setup

[](#routeros-setup)

Before enabling SSL in the client, the api-ssl service must be configured on your RouterOS device. A certificate is required.

Generate a self-signed certificate directly on the router:

```
/certificate add name=api-ssl common-name=api-ssl
/certificate sign api-ssl
/ip service set api-ssl certificate=api-ssl
/ip service enable api-ssl
```

Then allow connections by setting the allowed address under **IP → Services → api-ssl**.

### Client Configuration

[](#client-configuration)

```
$client = new Client([
    'host'      => '192.168.88.1',
    'username'  => 'admin',
    'password'  => 'secret',
    'ssl'       => true,
    'sslVerify' => false  // set to true if using a trusted certificate
]);
```

> **Note:** Most RouterOS devices use self-signed certificates. Set `sslVerify` to `false` unless you have installed a trusted certificate on your device.

---

Laravel Integration
-------------------

[](#laravel-integration)

This package includes a Service Provider for easy integration with Laravel applications.

### Laravel Installation

[](#laravel-installation)

Require the Laravel support package:

```
composer require illuminate/support
```

The Service Provider will be automatically discovered by Laravel.

### Laravel Configuration

[](#laravel-configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="Ocolin\RouterOS\Laravel\ServiceProvider"
```

This creates `config/routeros.php` in your Laravel application. Update your `.env` file with your device credentials: ROUTEROS\_HOST=192.168.88.1 ROUTEROS\_USERNAME=admin ROUTEROS\_PASSWORD=secret

### Laravel Usage

[](#laravel-usage)

The `Client` is automatically registered in Laravel's service container and can be injected into your controllers, services, or jobs:

```
use Ocolin\RouterOS\Client;

class NetworkController extends Controller
{
    public function __construct( private Client $client ) {}

    public function interfaces() : array
    {
        return $this->client->query( '/interface/print' );
    }
}
```

---

Migrating from routeros-api-php
-------------------------------

[](#migrating-from-routeros-api-php)

This library was designed as a maintained alternative to the widely used but unmaintained [routeros-api-php](https://github.com/EvilFreelancer/routeros-api-php)library. Several alias methods are included to ease migration.

### Method Aliases

[](#method-aliases)

routeros-api-phpocolin/routerosNotes`->where()``->query()`Alias included`->equal()``->attribute()`Alias included`->operations('|')``->or()`Alias included`->operations('&')``->and()`Alias included`->operations('!')``->not()`Alias included`->tag()`Coming in v2Not yet implemented### Configuration Differences

[](#configuration-differences)

The client is configured using an array or `Config` object rather than separate setter methods. The parameter names are similar but not identical:

routeros-api-phpocolin/routeros`host``host``user``username``pass``password``port``port``ssl``ssl``timeout``timeout``socket_timeout``socketTimeout`---

Roadmap
-------

[](#roadmap)

The following features are planned for future releases:

- **Concurrent commands** — multi-tag usage
- **Streaming cancellation** — explicit `/cancel` command support
- **CLI-style input** — parse RouterOS CLI syntax directly as command input
- **Laravel integration** — Facade for Laravel applications

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance94

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

6

Last Release

31d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e97ac0aa452b872ddc3f7f4c56c83852574a27bb74622f8c054d11ca20008fc9?d=identicon)[Ocolin](/maintainers/Ocolin)

---

Top Contributors

[![ocolin](https://avatars.githubusercontent.com/u/8870196?v=4)](https://github.com/ocolin "ocolin (5 commits)")

---

Tags

apinetworkrouterosmikrotik

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ocolin-routeros/health.svg)

```
[![Health](https://phpackages.com/badges/ocolin-routeros/health.svg)](https://phpackages.com/packages/ocolin-routeros)
```

###  Alternatives

[pear2/net_routeros

This package allows you to read and write information from a RouterOS host using MikroTik's RouterOS API.

249113.3k4](/packages/pear2-net-routeros)[ben-menking/routeros-api

Client API for RouterOS/Mikrotik

3786.5k](/packages/ben-menking-routeros-api)[m165437/laravel-blueprint-docs

API Blueprint Renderer for Laravel

22779.5k](/packages/m165437-laravel-blueprint-docs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
