RouterOS-api
Python API to RouterBoard devices produced by MikroTik.
Welcome to RouterOs Api
Python API to RouterBoard devices produced by MikroTik.
Usage
Connection
#!/usr/bin/python
import routeros_api
connection = routeros_api.RouterOsApiPool('IP', username='admin', password='')
api = connection.get_api()
Connect Options
routeros_api.RouterOsApiPool(
host,
username='admin',
password='',
port=8728,
use_ssl=False,
ssl_verify=True,
ssl_verify_hostname=True,
ssl_context=None,
)
Parameters:
host- String - Hostname or IP of device
Optional Parameters:
username- String - Login username - Default 'admin'password- String - Login password - Default empty stringport- Integer - TCP Port for API - Default 8728 or 8729 when using SSLplaintext_login- Boolean - Try plaintext login (for RouterOS 6.43 onwards) - Default Falseuse_ssl- Boolean - Use SSL or not? - Default Falsessl_verify- Boolean - Verify the SSL certificate? - Default Truessl_verify_hostname- Boolean - Verify the SSL certificate hostname matches? - Default Truessl_context- Object - Pass in a custom SSL context object. Overrides other options. - Default None
Using SSL
If we want to use SSL, we can simply specify use_ssl as True:
connection = routeros_api.RouterOsApiPool('<IP>', username='admin', password='', use_ssl=True)
This will automatically verify SSL certificate and hostname.
The most flexible way to modify SSL parameters is to provide an SSL Context object using the
ssl_context parameter, but for typical use-cases with self-signed certificates, the shorthand options of
ssl_verify and ssl_verify_hostname are provided.
e.g. if using a self-signed certificate, you can (but probably shouldn't) use:
connection = routeros_api.RouterOsApiPool(
'<IP>',
username='admin',
password='',
use_ssl=True,
ssl_verify=False,
ssl_verify_hostname=False,
)
Login for RouterOS v6.43 onwards
RouterOS Versions v6.43 onwards now use a different login method.
The disadvantage is that it passes the password in plain text.
For security we only attempt the plaintext login if requested using the plaintext_login parameter.
It is highly recommended only to use this option with SSL enabled.
routeros_api.RouterOsApiPool(host, username='admin', password='', plaintext_login=True)
Execute Commands
Call this with a resource and parameters as name/value pairs.
api.get_binary_resource('/').call('<resource>',{ <dict of params> })
Examples
api.get_binary_resource('/').call('tool/fetch',{ 'url': "https://dummy.url" })
api.get_binary_resource('/').call('ping', { 'address': '192.168.56.1', 'count': '4' })
Fetch List/Resource
list = api.get_resource('/command')
Example
list_queues = api.get_resource('/queue/simple')
Show all elements
list_queues.get()
Add rules
list.add(attribute="vale", attribute_n="value")
NOTE: Atributes with -, like max-limit use underscore _: max_limit
Example:
list_queues.add(name="001", max_limit="512k/4M", target="192.168.10.1/32")
Update Values
list.set(id, attributes)
Example:
list_queues.set(id="*2", name="jhon")
Get element:
list.get(attribute=value)
Example:
list_queues.get(name="jhon")
Remove element:
list.remove(id)
Example:
list_queues.remove(id="*2")
Close conection:
connection.disconnect()
Other Example:
list_address = api.get_resource('/ip/firewall/address-list')
list_address.add(address="192.168.0.1",comment="P1",list="10M")
list_address.get(comment="P1")
list_address.remove(id="*7")
Metadata
Release files for RouterOS-api 0.16.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| RouterOS-api-0.16.0.tar.gz | 11.4 kB | Without provenance | Details for RouterOS-api-0.16.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| RouterOS_api-0.16.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for RouterOS_api-0.16.0-py2.py3-none-any.whl |
Total release size: 31.5 kB
Release files / RouterOS-api-0.16.0.tar.gz
| Download URL | RouterOS-api-0.16.0.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27adcc48ec6006d13348b4fb1e0e56021cb62d8af49901a70811c03c702f9c32
|
|
BLAKE2b-256 checksum How to use checksums |
10d91985f934346b16f8290e3d1151442800cfb7008138d99b8de2549de38a16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.1
|
Release files / RouterOS_api-0.16.0-py2.py3-none-any.whl
| Download URL | RouterOS_api-0.16.0-py2.py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
18a177819e5b0fa42c2cd549357b4f190a330a6112c3b3c9b745e6df33746274
|
|
BLAKE2b-256 checksum How to use checksums |
938dcfe436b849641afc3dbbc57b493905ddeb77d0126f6cdacdce70493a7506
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.1
|
Security for RouterOS-api 0.16.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.