https://github.com/karolba/lua-mikrotik
A Lua library for talking to the Mikrotik RouterOS API
https://github.com/karolba/lua-mikrotik
lua mikrotik routeros
Last synced: about 1 month ago
JSON representation
A Lua library for talking to the Mikrotik RouterOS API
- Host: GitHub
- URL: https://github.com/karolba/lua-mikrotik
- Owner: karolba
- License: mit
- Created: 2018-09-15T17:21:36.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-02T13:37:20.000Z (over 6 years ago)
- Last Synced: 2025-06-04T19:24:26.420Z (4 months ago)
- Topics: lua, mikrotik, routeros
- Language: Lua
- Homepage:
- Size: 12.7 KB
- Stars: 3
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-mikrotik
A lightweight lua library for talking to the [Mikrotik RouterOS API](https://wiki.mikrotik.com/wiki/Manual:API).
## Requirements:
* Either:
* [luasocket](https://github.com/diegonehab/luasocket)
* Either the [kikito's md5 library](https://github.com/kikito/md5.lua) or the [keplerproject's md5 library](https://github.com/keplerproject/md5)
* On older Lua versions with no `bit32` (`<= 5.1`), either [BitOp](http://luaforge.net/projects/bit/), or [BitLib](https://github.com/LuaDist/bitlib)
* or [OpenResty](https://openresty.org/en/), which contains all these dependencies.## Documentation:
For documentation see [doc/api.md](https://github.com/karolba/lua-mikrotik/blob/master/doc/api.md).
## Examples:
Starting a RouterOS script from `/system/script` by name synchronously:
```lua
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!')
endlocal 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:
```lua
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))
endlocal mt = assert(Mikrotik:create('192.168.88.1'))
assert(mt:login('login', 'password'), 'Failed login')runScript(mt, 'example-routeros-script-name')
assert(mt:wait())
```