anandaerditya / routeros-api-php
Mikrotik RouterOS API Communicator Module for PHP
Requires
- php: ^8.0
- evilfreelancer/routeros-api-php: ^1.5
Requires (Dev)
README
This library is using API Client Communicator under PHP Socket, thanks to the repository from EvilFreelance. This library provides built-in methods based on the available configuration under Winbox, with their respective commands and parameters. At the moment, this library supports RouterBoard and Cloud Router Switch with pre-6.43 and post-6.43 versions of RouterOS, as mentioned in this repository.
Changelog
1.6.2 ( Enhancement, Feature )
-
Update commands and their parameters into the following methods:
router_switch()
,router_switch_port()
,router_switch_port_isolation()
,
-
Add new methods :
router_switch_rule()
1.5.3 ( Bugfix, Feature )
- Add new methods :
system_resource()
,system_resource_cpu()
,system_resource_irq()
,system_resource_pci()
,system_resource_usb()
,interface_bridge_calea()
,interface_bridge_filter()
,
1.5.3 ( Bugfix )
- Add message handler for
!trap
,!re
,!done
, and!fatal
type under thesend()
method.
1.4.2 ( Bugfix )
- Fix Mikrotik API response message handling under
send()
method;
1.3.22 ( Hotfix )
- Add new Exception : ErrorException;
- Add error handler for each method to catch any errors under mikrotik API.
- Add new methods :
ip_dhcp_server_lease()
ip_arp()
router_switch()
router_switch_port()
Requirements
PHP
: Version 8.0 and upext-sockets
: A Socket extension for PHPRouterOS
: pre-6.43 and post-6.43 (Tested on RouterBoard and Cloud Router Switch device)
How to Install
Under composer, just copy this command to begin add this library into your project.
composer require anandaerditya/routeros-api-php
Using the Library
If you are using Composer Project such Laravel Framework, you can just call the library under Erditya\RouterOSInstance
class. As follows :
include 'vendor/autoload.php'; use Erditya\RouterOSInstance; $router = new RouterOSInstance(); # Create connection $router = $router->connect( [ 'host' => '192.168.10.1', 'user' => 'username', 'pass' => 'password', 'port' => 8728 ] ); # Example : Fetch all IP Addresses if ($router->is_connected()) { # Get All Addresses var_dump($router->ip_addresses()); # Get address with interface ether2 var_dump($router->ip_addresses(['interface' => 'ether2'])); # Update address item in ID *2 var_dump($router->ip_addresses('set', [ '.id' => '*2', 'comment' => 'Some Comments' ])); }
Or, another way to approach :
include 'vendor/autoload.php'; use Erditya\RouterOSInstance; $router = new RouterOSInstance(); # Create connection $router = $router->connect( [ 'host' => '192.168.10.1', 'user' => 'username', 'pass' => 'password', 'port' => 8728 ] ); # Get All Addresses var_dump($router->ip_addresses()); # Get address with interface ether2 var_dump($router->ip_addresses(['interface' => 'ether2'])); # Update address item in ID *2 var_dump($router->ip_addresses('set', [ '.id' => '*2', 'comment' => 'Some Comments' ]));
Available Methods
List of all methods available in this library at this version :
-
General
connect()
is_connected()
-
Interface
interface_bridge()
interface_bridge_port()
interface_bridge_port()
interface_ethernet()
interface_list()
interface_list_member()
interface_vlan()
-
IP
ip_addresses()
ip_dhcp_server()
ip_dhcp_server_network()
ip_dns()
ip_firewall_filter()
ip_firewall_nat()
ip_hotspot_user_profiles()
ip_hotspot_users()
ip_hotspot_server_profiles()
ip_hotspot_servers()
ip_hotspot_ip_binding()
ip_pool()
ip_route()
ip_services()
-
System
system_identity()
system_user_groups()
system_users()
-
Switch (for Cloud Router Switch only)
switch_crs_egress_vlan_tag()
switch_crs_mac_based_vlan()
switch_crs_port()
Commands & Parameters, and Response
All the methods provided in this library are similar to Winbox's CLI terminal. You can check them under Winbox for more information. All the methods using the command print
as the default returned the response as an array. If you call the method using another command, such as add
, set
, remove
, etc., the method will return true
, which indicates it was successfully executed.