PHPackages                             bennito254/routeros-client - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. bennito254/routeros-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

bennito254/routeros-client
==========================

A modern, production-grade PHP client for MikroTik RouterOS API.

v0.0.1(3w ago)01MITPHPPHP &gt;=8.2CI passing

Since May 17Pushed 3w agoCompare

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

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

RouterOS Client
===============

[](#routeros-client)

A modern, production-grade PHP client for communicating with the MikroTik RouterOS API over raw sockets. Built for modern PHP 8.2+ with PSR-4 autoloading, strong typing, robust error handling, and proxy support out-of-the-box.

Features
--------

[](#features)

- **Modern Architecture**: Clean object-oriented design, completely uncoupled from heavy libraries.
- **Direct Sockets**: Communicates natively using raw TCP sockets, fully implementing the RouterOS length-encoded protocol. No cURL needed.
- **Proxy Support built-in**: First-class support for routing connections through SOCKS5 and HTTP CONNECT proxies. Handshake is performed natively.
- **TLS/SSL encryption**: Support for API-SSL with options to configure certificates and peer verification.
- **Query Builder**: Fluent `Query` builder for crafting RouterOS commands and filters easily.
- **Collections**: Responses are encapsulated in `ResponseCollection` containing `ResponseSentence` objects.
- **Service Facades**: Ready-to-use Facade classes to manage IP addresses, Hotspot clients, and PPP accounts fluently.
- **Laravel Integration**: Out-of-the-box support for Laravel with zero configuration required, complete with a service provider, facade, and published config.

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

[](#installation)

Install via Composer:

```
composer require bennito254/routeros-client
```

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

[](#basic-usage)

```
use Bennito254\RouterOS\Client\Client;
use Bennito254\RouterOS\Query\Query;

require 'vendor/autoload.php';

// Configure and connect
$client = new Client([
    'host' => '192.168.88.1',
    'username' => 'admin',
    'password' => 'password',
    'port' => 8728,
]);

// Send a command
$response = $client->query('/system/resource/print');

// Access results
foreach ($response->toArray() as $item) {
    echo "CPU Load: " . ($item['cpu-load'] ?? 'N/A') . "%\n";
}
```

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

[](#laravel-integration)

The package automatically discovers its Laravel service provider and registers itself. You can easily publish the configuration file to customize your connection settings:

```
php artisan vendor:publish --tag="routeros-config"
```

Once published to `config/routeros.php`, update your `.env` file:

```
ROUTEROS_HOST=192.168.88.1
ROUTEROS_USERNAME=admin
ROUTEROS_PASSWORD=secret
```

You can then utilize the Laravel `RouterOS` Facade anywhere in your application:

```
use Bennito254\RouterOS\Laravel\Facade as RouterOS;

$response = RouterOS::query('/ip/address/print');
```

Service Facades
---------------

[](#service-facades)

The package provides dedicated Service Facades allowing you to rapidly query, add, modify, or toggle states on RouterOS entities (such as IP Addresses, Hotspot Users, and PPP Secrets) without manually constructing queries.

```
use Bennito254\RouterOS\Facade\IpAddress;
use Bennito254\RouterOS\Facade\HotspotUser;

// Using the IpAddress Facade
$ipFacade = new IpAddress($client);

// Get all IP Addresses
$addresses = $ipFacade->getAll();

// Add a new IP Address
$ipFacade->add([
    'address'   => '10.0.0.1/24',
    'interface' => 'ether2',
]);

// Disable a Hotspot user by their RouterOS `.id`
$hotspotFacade = new HotspotUser($client);
$hotspotFacade->disable('*1F');
```

The available built-in Facades under `Bennito254\RouterOS\Facade\` are:

- `IpAddress` (`/ip/address`)
- `HotspotUser` (`/ip/hotspot/user`)
- `HotspotActive` (`/ip/hotspot/active`)
- `PppSecret` (`/ppp/secret`)
- `PppActive` (`/ppp/active`)

Using the Query Builder
-----------------------

[](#using-the-query-builder)

```
$query = Query::make('/ip/address/print')
    ->where('interface', 'ether1')
    ->equal('disabled', false)
    ->tag('my-request');

$response = $client->query($query);
```

Connecting Through a Proxy
--------------------------

[](#connecting-through-a-proxy)

Connect to your Mikrotik behind a restrictive network using a SOCKS5 proxy:

```
$client = new Client([
    'host' => '192.168.88.1',
    'username' => 'admin',
    'password' => 'password',
    'proxy' => [
        'type' => 'socks5',
        'host' => '127.0.0.1',
        'port' => 1080,
        // 'username' => 'proxyuser',
        // 'password' => 'proxypass',
    ],
]);
```

You can also use an HTTP CONNECT proxy by changing `type` to `'http'`.

Connecting via API-SSL
----------------------

[](#connecting-via-api-ssl)

Enable SSL to connect securely using the API-SSL port (default 8729).

```
$client = new Client([
    'host' => '192.168.88.1',
    'username' => 'admin',
    'password' => 'password',
    'port' => 8729,
    'ssl' => [
        'enabled' => true,
        'verify_peer' => false, // Set to true in production
    ],
]);
```

Error Handling
--------------

[](#error-handling)

The package provides a robust exception hierarchy under `Bennito254\RouterOS\Exception`:

- `ConnectionException`: Network issues, timeouts, and socket errors.
- `AuthenticationException`: Invalid credentials.
- `ProxyException`: Errors during SOCKS5 or HTTP CONNECT handshake.
- `ProtocolException`: Corrupted length encoding or malformed sentences.
- `TrapException`: Errors returned by RouterOS (`!trap`).
- `FatalException`: Fatal errors from RouterOS (`!fatal`).

Example:

```
use Bennito254\RouterOS\Exception\TrapException;

try {
    $client->query('/invalid/command');
} catch (TrapException $e) {
    echo "RouterOS Error: " . $e->getMessage();
}
```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance95

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

23d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/687082c4c697d13f21c03c1443459e16897bc94c98e6eb87fa87def757336504?d=identicon)[bennito254](/maintainers/bennito254)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/http-kernel

Provides a structured process for converting a Request into a Response

8.1k853.6M8.2k](/packages/symfony-http-kernel)[symfony/http-client

Provides powerful methods to fetch HTTP resources synchronously or asynchronously

2.1k330.1M4.5k](/packages/symfony-http-client)[zircote/swagger-php

Generate interactive documentation for your RESTful API using PHP attributes (preferred) or PHPDoc annotations

5.4k140.4M553](/packages/zircote-swagger-php)[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k66.1M251](/packages/nelmio-api-doc-bundle)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[api-platform/metadata

API Resource-oriented metadata attributes and factories

244.5M180](/packages/api-platform-metadata)

PHPackages © 2026

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