Name | routeros-api-fork JSON |
Version |
0.19.0
JSON |
| download |
home_page | None |
Summary | Python API to RouterBoard devices produced by MikroTik. |
upload_time | 2024-11-03 17:08:26 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT |
keywords |
api
mikrotik
routeros
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# RouterOS-api
Python API to RouterBoard devices produced by [MikroTik](https://mikrotik.com/) written by [Social WiFi](https://socialwifi.com).
## Usage
### Connection
```python
#!/usr/bin/python
import routeros_api_fork
connection = routeros_api_fork.RouterOsApiPool('IP', username='admin', password='')
api = connection.get_api()
```
#### Connect Options
```python
routeros_api_fork.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 string
* `port` - Integer - TCP Port for API - Default 8728 or 8729 when using SSL
* `plaintext_login` - Boolean - Try plaintext login (for RouterOS 6.43 onwards) - Default **False**
* `use_ssl` - Boolean - Use SSL or not? - Default **False**
* `ssl_verify` - Boolean - Verify the SSL certificate? - Default **True**
* `ssl_verify_hostname` - Boolean - Verify the SSL certificate hostname matches? - Default **True**
* `ssl_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`:
```python
connection = routeros_api_fork.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:
```python
connection = routeros_api_fork.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.
```python
routeros_api_fork.RouterOsApiPool(host, username='admin', password='', plaintext_login=True)
```
### Execute Commands
Call this with a resource and parameters as name/value pairs.
```python
api.get_binary_resource('/').call('<resource>',{ <dict of params> })
```
#### Examples
```python
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
```python
list = api.get_resource('/command')
```
#### Example
```python
list_queues = api.get_resource('/queue/simple')
```
#### Show all elements
```python
list_queues.get()
```
### Add rules
```python
list.add(attribute="vale", attribute_n="value")
```
**NOTE**: Atributes with `-`, like `max-limit` use underscore `_`: `max_limit`
#### Example:
```python
list_queues.add(name="001", max_limit="512k/4M", target="192.168.10.1/32")
```
### Update Values
```python
list.set(id, attributes)
```
#### Example:
```python
list_queues.set(id="*2", name="jhon")
```
### Get element:
```python
list.get(attribute=value)
```
#### Example:
```python
list_queues.get(name="jhon")
```
### Remove element:
```python
list.remove(id)
```
#### Example:
```python
list_queues.remove(id="*2")
```
### Close conection:
```python
connection.disconnect()
```
### Run script and get output
The example script only prints "hello". Here's a simplifed example of how to run it and get the output:
```
>>> api.get_resource("/system/script").get()[0]['source']
'/put "hello"'
>>> async_response = api.get_binary_resource('/').call('system/script/run', {"number": '0'.encode('utf-8')})
>>> async_response.__dict__
{'command': <routeros_api_fork.sentence.CommandSentence object at 0x73a0f2b3eba0>, 'done_message': {'ret': b'hello'}, 'done': True, 'error': None}
>>> async_response.done_message['ret']
b'hello'
```
### Other Example:
```python
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")
```
Raw data
{
"_id": null,
"home_page": null,
"name": "routeros-api-fork",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "API, MikroTik, RouterOS",
"author": null,
"author_email": "Pavel Korchagin <xoste49@gmail.com>, Social WiFi <it@socialwifi.com>",
"download_url": "https://files.pythonhosted.org/packages/ba/4e/f7b5118f5725ee28a702d0f6f78cce30a13f693826a89c63094c28a9cd7f/routeros_api_fork-0.19.0.tar.gz",
"platform": null,
"description": "# RouterOS-api\n\nPython API to RouterBoard devices produced by [MikroTik](https://mikrotik.com/) written by [Social WiFi](https://socialwifi.com).\n\n## Usage\n\n### Connection\n\n```python\n#!/usr/bin/python\n\nimport routeros_api_fork\n\nconnection = routeros_api_fork.RouterOsApiPool('IP', username='admin', password='')\napi = connection.get_api()\n```\n\n#### Connect Options\n\n```python\nrouteros_api_fork.RouterOsApiPool(\n host,\n username='admin',\n password='',\n port=8728,\n use_ssl=False,\n ssl_verify=True,\n ssl_verify_hostname=True,\n ssl_context=None,\n)\n```\n\nParameters:\n\n* `host` - String - Hostname or IP of device\n\nOptional Parameters:\n\n* `username` - String - Login username - Default 'admin'\n* `password` - String - Login password - Default empty string\n* `port` - Integer - TCP Port for API - Default 8728 or 8729 when using SSL\n* `plaintext_login` - Boolean - Try plaintext login (for RouterOS 6.43 onwards) - Default **False**\n* `use_ssl` - Boolean - Use SSL or not? - Default **False**\n* `ssl_verify` - Boolean - Verify the SSL certificate? - Default **True**\n* `ssl_verify_hostname` - Boolean - Verify the SSL certificate hostname matches? - Default **True**\n* `ssl_context` - Object - Pass in a custom SSL context object. Overrides other options. - Default **None**\n\n#### Using SSL\n\nIf we want to use SSL, we can simply specify `use_ssl` as `True`:\n\n```python\nconnection = routeros_api_fork.RouterOsApiPool('<IP>', username='admin', password='', use_ssl=True)\n```\n\nThis will automatically verify SSL certificate and hostname. \nThe most flexible way to modify SSL parameters is to provide an SSL Context object using the \n`ssl_context` parameter, but for typical use-cases with self-signed certificates, the shorthand options of\n `ssl_verify` and `ssl_verify_hostname` are provided.\n\ne.g. if using a self-signed certificate, you can (but probably shouldn't) use:\n\n```python\nconnection = routeros_api_fork.RouterOsApiPool(\n '<IP>',\n username='admin',\n password='',\n use_ssl=True,\n ssl_verify=False,\n ssl_verify_hostname=False,\n)\n```\n\n#### Login for RouterOS v6.43 onwards\n\nRouterOS Versions v6.43 onwards now use a different login method. \nThe disadvantage is that it passes the password in plain text. \nFor security we only attempt the plaintext login if requested using the `plaintext_login` parameter. \nIt is highly recommended only to use this option with SSL enabled.\n\n```python\nrouteros_api_fork.RouterOsApiPool(host, username='admin', password='', plaintext_login=True)\n```\n\n### Execute Commands\n\nCall this with a resource and parameters as name/value pairs.\n\n```python\napi.get_binary_resource('/').call('<resource>',{ <dict of params> })\n```\n\n#### Examples\n\n```python\napi.get_binary_resource('/').call('tool/fetch',{ 'url': \"https://dummy.url\" })\napi.get_binary_resource('/').call('ping', { 'address': '192.168.56.1', 'count': '4' })\n```\n\n### Fetch List/Resource\n\n```python\nlist = api.get_resource('/command')\n```\n\n#### Example\n\n```python\nlist_queues = api.get_resource('/queue/simple')\n```\n\n#### Show all elements\n\n```python\nlist_queues.get()\n```\n\n### Add rules\n\n```python\nlist.add(attribute=\"vale\", attribute_n=\"value\")\n```\n\n**NOTE**: Atributes with `-`, like `max-limit` use underscore `_`: `max_limit`\n\n#### Example:\n\n```python\nlist_queues.add(name=\"001\", max_limit=\"512k/4M\", target=\"192.168.10.1/32\")\n```\n\n### Update Values\n\n```python\nlist.set(id, attributes)\n```\n\n#### Example:\n\n```python\nlist_queues.set(id=\"*2\", name=\"jhon\")\n```\n\n### Get element:\n\n```python\nlist.get(attribute=value)\n```\n\n#### Example:\n\n```python\nlist_queues.get(name=\"jhon\")\n```\n\n### Remove element:\n\n```python\nlist.remove(id)\n```\n\n#### Example:\n\n```python\nlist_queues.remove(id=\"*2\")\n```\n\n### Close conection:\n\n```python\nconnection.disconnect()\n```\n\n### Run script and get output\n\nThe example script only prints \"hello\". Here's a simplifed example of how to run it and get the output:\n\n```\n>>> api.get_resource(\"/system/script\").get()[0]['source']\n'/put \"hello\"'\n>>> async_response = api.get_binary_resource('/').call('system/script/run', {\"number\": '0'.encode('utf-8')})\n>>> async_response.__dict__\n{'command': <routeros_api_fork.sentence.CommandSentence object at 0x73a0f2b3eba0>, 'done_message': {'ret': b'hello'}, 'done': True, 'error': None}\n>>> async_response.done_message['ret']\nb'hello'\n```\n\n### Other Example:\n\n```python\nlist_address = api.get_resource('/ip/firewall/address-list')\nlist_address.add(address=\"192.168.0.1\",comment=\"P1\",list=\"10M\")\n\nlist_address.get(comment=\"P1\")\n\nlist_address.remove(id=\"*7\")\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python API to RouterBoard devices produced by MikroTik.",
"version": "0.19.0",
"project_urls": {
"Homepage": "https://github.com/xoste49/RouterOS-api-fork"
},
"split_keywords": [
"api",
" mikrotik",
" routeros"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "b475b208ff5b5056d6f68885254b568d68749574b924fb9d8d14102e45e75cb2",
"md5": "b631dfb7543691e6b59635e9aa2cd3ab",
"sha256": "3b094940a24d6c7f8a54bba8e3d193d071cea049de0e15ca7cd0f5a661529424"
},
"downloads": -1,
"filename": "routeros_api_fork-0.19.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b631dfb7543691e6b59635e9aa2cd3ab",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 16599,
"upload_time": "2024-11-03T17:08:25",
"upload_time_iso_8601": "2024-11-03T17:08:25.329149Z",
"url": "https://files.pythonhosted.org/packages/b4/75/b208ff5b5056d6f68885254b568d68749574b924fb9d8d14102e45e75cb2/routeros_api_fork-0.19.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ba4ef7b5118f5725ee28a702d0f6f78cce30a13f693826a89c63094c28a9cd7f",
"md5": "2534db4b17cfa341ee4a9dacfed2c0f9",
"sha256": "66e7b98db787112adf1932e69c92575037bd59f3951eafe195ea63459425f21b"
},
"downloads": -1,
"filename": "routeros_api_fork-0.19.0.tar.gz",
"has_sig": false,
"md5_digest": "2534db4b17cfa341ee4a9dacfed2c0f9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 18233,
"upload_time": "2024-11-03T17:08:26",
"upload_time_iso_8601": "2024-11-03T17:08:26.343112Z",
"url": "https://files.pythonhosted.org/packages/ba/4e/f7b5118f5725ee28a702d0f6f78cce30a13f693826a89c63094c28a9cd7f/routeros_api_fork-0.19.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-03 17:08:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "xoste49",
"github_project": "RouterOS-api-fork",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "routeros-api-fork"
}