Skip to content
A Lua library for talking to the Mikrotik RouterOS API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc
rockspecs
LICENSE
Mikrotik.lua
README.md

README.md

lua-mikrotik

A lightweight lua library for talking to the Mikrotik RouterOS API.

Requirements:

Documentation:

For documentation see doc/api.md.

Examples:

Starting a RouterOS script from /system/script by name synchronously:

local Mikrotik = require 'Mikrotik'

local function runScript(mt, scriptname)
    assert(mt:sendSentence({ '/system/script/print', '?name=' .. scriptname, '=.proplist=.id' }))

    local message = assert(mt:readSentence())
    assert(message.type == '!re')
    assert(mt:readSentence().type == '!done')

    assert(mt:sendSentence({ '/system/script/run', '=number=' .. message['=.id']}))
    assert(mt:readSentence().type == '!done')

    print('OK!')
end

local mt = assert(Mikrotik:create('192.168.88.1'))
assert(mt:login('login', 'password'), 'Failed login')

runScript(mt, 'example-routeros-script-name')

The same result can be accomplished by using "tagged sentences" and callbacks:

local Mikrotik = require 'Mikrotik'

local function runScript(mt, scriptname)
    assert(mt:sendSentence({ '/system/script/print', '?name=' .. scriptname, '=.proplist=.id' }, function(res)
        if res.type == '!re' then
            assert(mt:sendSentence({ '/system/script/run', '=number=' .. res['=.id'] }, function(res)
                if res.type == '!done' then
                    print('OK!')
                end
            end))
        end
    end))
end

local mt = assert(Mikrotik:create('192.168.88.1'))
assert(mt:login('login', 'password'), 'Failed login')

runScript(mt, 'example-routeros-script-name')

assert(mt:wait())
You can’t perform that action at this time.