Mikrotik Api Examples [ORIGINAL]
import ssl ssl_context = ssl.create_default_context() api_ssl = librouteros.connect( host='192.168.88.1', username='admin', password='', port=8729, use_ssl=True, ssl_wrapper=ssl_context )
Try the examples above, then modify them to fit your network. Next week, I’ll cover for live graphing. mikrotik api examples
If you manage more than one MikroTik router, logging into WinBox or WebFig for every small change gets old fast. The MikroTik API lets you script configuration, gather data, and react to network events — all from your own code. import ssl ssl_context = ssl
def toggle_rule(comment, enable=True): rule = api(cmd='/ip/firewall/filter/print', .proplist='.id', comment=comment) if rule: cmd = '/ip/firewall/filter/enable' if enable else '/ip/firewall/filter/disable' api(cmd, .id=rule[0]['.id']) print(f"Rule '{comment}' {'enabled' if enable else 'disabled'}") toggle_rule('block-torrent', enable=False) Example 4: Get Active Connections by Protocol Monitor live traffic from Python. ssl_wrapper=ssl_context ) Try the examples above
