PRACTICAL PATHOLOGY(WITH VIVA VOCE) By: Tejinder Singh & Uma Chaturvedi


def monitor_interface(interface='ether1', interval=1): cmd = '/interface/monitor-traffic' while True: data = api(cmd, 'interface': interface, 'once': '') print(f"RX: data[0]['rx-bits-per-second'] bps TX: data[0]['tx-bits-per-second'] bps") time.sleep(interval)

This code creates a new VLAN with the name vlan10 , VLAN ID 10 , and interface ether1 . It then sets the IP address for the VLAN to 192.168.10.1/24 .

| Action | API Path | Example | |--------|----------|---------| | Get interfaces | /interface/print | connection.path('interface').get() | | Add simple queue | /queue/simple/add | add(name='queue1', target='10.0.0.5', max_limit='2M/2M') | | Remove by ID | /ip/address/remove | .path('ip', 'address').remove('.id=*1') | | Set DNS server | /ip/dns/set | set(servers='8.8.8.8', allow_remote_requests='yes') |

identity = api.get_resource('/system/identity').get() print(f"Router Name: identity[0]['name']")

print(mikrotik_cmd('192.168.88.1', 8728, 'admin', '', '/interface/print'))

MikroTik offers two primary ways to interact with its devices programmatically: the legacy binary API (for high-performance tasks) and the modern introduced in RouterOS v7. 1. Modern REST API (RouterOS v7+)