A Java client implementation for the Mikrotik RouterOS API.
Go to file
GideonLeGrange f242144496 Added complex async exmple 2013-12-23 11:52:07 +02:00
src/main/java Added complex async exmple 2013-12-23 11:52:07 +02:00
.gitignore Changed .gitignore 2013-12-20 21:32:05 +02:00
LICENCE.md Update LICENCE.md 2013-07-16 21:06:25 +02:00
README.md Fixed error in README 2013-09-22 21:26:32 +02:00
pom.xml Added complex async exmple 2013-12-23 11:52:07 +02:00

README.md

mikrotik-java

A Java client implementation for the Mikrotik RouterOS API.

This project provides a Java client to manipulate Mikrotik routers using the remote API. Simple things must be easy to do, and complex things must be possible.

This code is currently pre-release, so in order to use it you will have to clone it locally and compile it yourself. Any part, including public interfaces, can change at any time, until I release version 1.0.

Examples

Here is a simple example: Connect to a router and reboot it.

ApiConnection con = ApiConnection.connect("10.0.1.1"); // connect to router
con.login("admin","password"); // log in to router
con.execute("/system/reboot"); // execute a command
con.disconnect(); // disconnect from router

A simple example that returns a result: Print all interfaces.

List<Map<String, String>> rs = con.execute("/interface/print");
for (Map<String,String> r : rs) {
  System.out.println(r);
}

The same query, but with the results filtered: Print all interfaces of type 'vlan'.

List<Map<String, String>> rs = con.execute("/interface/print where type=vlan");

The same query, but we only want certain result fields names Print all interfaces of type 'vlan' and return their name.

List<Map<String, String>> rs = con.execute("/interface/print where type=vlan return name");

We can run asynchrynous commands:

This example shows how to run '/interface wireless monitor' and have the result sent to a listener object, which prints it

String tag = con.execute("/interface/wireless/monitor .id=wlan1 return signal-to-noise", 
      new ResultListener() {

            public void receive(Map<String, String> result) {
                System.out.println(result);
            }
            
        }
  );

The above command will run and send results asynchrynously as they become available, until it is canceled. The command (identified by the unique String retruned) is cancelled like this:

con.cancel(tag);

More examples will be added shortly.

TODO

For 1.0:

  • More examples
  • More formal documentation
  • Push Javadoc to GitHub
  • Get into Maven Central

Later:

  • SSL support.

References

The RouterOS API is documented here: http://wiki.mikrotik.com/wiki/Manual:API

Licence

This library is released under the Apache 2.0 licence. See the Licence.md file