PHP code example of anandaerditya / routeros-api-php

1. Go to this page and download the library: Download anandaerditya/routeros-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

anandaerditya / routeros-api-php example snippets


     
    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'
        ]));
    }

     
    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'
    ]));