Connect¶
Unencrypted¶
from librouteros import connect
api = connect(
username='admin',
password='abc',
host='some.address.com',
)
Encrypted¶
Before connecting, api-ssl
service on routeros must be enabled.
For more information on how to generate certificates see
MikroTik wiki.
After that, create your default SSLContext
and fine tune for your needs. Code below allows connecting to API without ceritficate.
import ssl
from librouteros import connect
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.set_ciphers('ADH:@SECLEVEL=0')
api = connect(
username='admin',
password='abc',
host='some.address.com',
ssl_wrapper=ctx.wrap_socket,
port=8729
)
If you need to pass any other parameters like server_name
,
use partial.
from functools import partial
ssl_wrapper=partial(ctx.wrap_socket, server_hostname='some.address.com')
Auth methods¶
Starting from routeros 6.43
, token auth method was replaced by plain text.
By default library will use plain text method. You can force library to use token method:
from librouteros.login import plain, token
# for post 6.42 (plain text password)
method = plain
# for pre 6.43 (with token)
method = token
api = connect(username='admin', password='abc', host='some.address.com', login_method=method)
Note
Library will not try different methods untill it will log in.