Mikrotik Api Examples Now
Board: RB750Gr3 Uptime: 3d5h12m CPU Load: 7% Automating DHCP reservations.
api(cmd='/ip/dhcp-server/lease/add', address='192.168.88.50', mac_address='AA:BB:CC:DD:EE:FF', comment='printer-api') To verify: mikrotik api examples
import librouteros api = librouteros.connect( host='192.168.88.1', username='admin', password='', port=8728, # default API port (plaintext) use_ssl=False ) resources = api(cmd='/system/resource/print') print(f"Board: {resources[0]['board-name']}") print(f"Uptime: {resources[0]['uptime']}") print(f"CPU Load: {resources[0]['cpu-load']}%") Board: RB750Gr3 Uptime: 3d5h12m CPU Load: 7% Automating
Make sure /ip service set api-ssl disabled=no is enabled on the router. RouterOS 7.14 introduced REST API, but the classic API also works fine. For large networks, try async: mikrotik api examples
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 )
Let me know in the comments. Want the code as a ready-to-use Python script? Download the gist here.