Crate mikrotik_rs

Source
Expand description

§MikroTik-rs

mikrotik-rs is an asynchronous Rust library for interfacing with MikroTik routers. It allows for sending commands and receiving responses in parallel through channels.

§Features

  • Asynchronous command execution
  • Parallel command handling with responses through channels
  • Non-blocking communication with the router

§Examples

Basic usage:

use mikrotik_rs::{protocol::command::CommandBuilder, MikrotikDevice};
use tokio;

#[tokio::main]
async fn main() -> io::Result<()> {
    // Router's address with port
    let addr = "192.168.88.1:8728";

    // Router's username and password
    let username = "admin";
    let password = "password";

    let mut client = MikrotikDevice::connect(addr, username, Some(password)).await?;

    let command = CommandBuilder::new().command("/interface/print").build(); // Example command
    let response_channel = client.send_command(command).await?;
    while let Some(response) = response_channel.recv().await {
       println!("{:?}", response);
    }
}

§Usage

Add this to your Cargo.toml:

[dependencies]
mikrotik-rs = "0.1"
tokio = { version = "1", features = ["full"] }

§Note

This library requires the tokio runtime.

Modules§

error
Error module for handling errors during device operations.
macros
Macros module to make your life easier.
protocol
Protocol module for handling MikroTik API communication.

Macros§

command
Macro that enforces Mikrotik command syntax at compile time.

Structs§

MikrotikDevice
A client for interacting with MikroTik devices.