|
|
|
@ -1,3 +1,8 @@ |
|
|
|
[](https://packagist.org/packages/evilfreelancer/routeros-api-php) |
|
|
|
[](https://packagist.org/packages/evilfreelancer/routeros-api-php) |
|
|
|
[](https://packagist.org/packages/evilfreelancer/routeros-api-php) |
|
|
|
[](https://scrutinizer-ci.com/g/evilfreelancer/routeros-api-php/) |
|
|
|
|
|
|
|
# RouterOS PHP7 API Client |
|
|
|
|
|
|
|
composer require evilfreelancer/routeros-api-php |
|
|
|
@ -54,6 +59,42 @@ $response = $client->write($query)->read(); |
|
|
|
var_dump($response); |
|
|
|
``` |
|
|
|
|
|
|
|
### How to write queries |
|
|
|
|
|
|
|
You can write absolutely any queries to your router, for this you |
|
|
|
need to create a "Query" object whose first argument is the |
|
|
|
required command, after this you can add the attributes of the |
|
|
|
command to "Query" object. |
|
|
|
|
|
|
|
More about attributes and "words" from which this attributes |
|
|
|
should be created [here](https://wiki.mikrotik.com/wiki/Manual:API#Command_word). |
|
|
|
|
|
|
|
```php |
|
|
|
use \RouterOS\Query; |
|
|
|
|
|
|
|
// One line query: Get all packages |
|
|
|
$query = new Query('/system/package/getall'); |
|
|
|
|
|
|
|
// Multiline query: Enable interface and add tag |
|
|
|
$query = new Query('/interface/set'); |
|
|
|
$query |
|
|
|
->add('=disabled=no') |
|
|
|
->add('=.id=ether1') |
|
|
|
->add('.tag=4'); |
|
|
|
|
|
|
|
// Multiline query: Get all ethernet and VLAN interfaces |
|
|
|
$query = new Query('/interface/print'); |
|
|
|
$query |
|
|
|
->add('?type=ether') |
|
|
|
->add('?type=vlan') |
|
|
|
->add('?#|'); |
|
|
|
|
|
|
|
// Multiline query: Get all routes that have non-empty comment |
|
|
|
$query = new Query('/ip/route/print'); |
|
|
|
$query |
|
|
|
->add('?>comment='); |
|
|
|
``` |
|
|
|
|
|
|
|
## Links |
|
|
|
|
|
|
|
* [Cloud Hosted Router](https://mikrotik.com/download#chr) - Virtual images of RouterOS for your hypervisor |
|
|
|
|