Skip to content
Danik edited this page Jun 16, 2026 · 40 revisions

tik4net

tik4net is a .NET library for talking to MikroTik RouterOS devices. It scales from raw API access up to a fully typed O/R mapper, all behind one ITikConnection interface.

🆕 Heads-up — this wiki documents the unreleased 4.x line. Items tagged 4.x below are on the 4.x development branch and are not in a public NuGet release yet; their API and behaviour may still change. The current stable release is 3.6.0. New non-API transports (SSH, Telnet, MAC-Telnet, WinBox, REST) are alpha previews — see Connection types & capabilities.


Install

dotnet add package tik4net.entities   # high-level O/R mapper (pulls in tik4net automatically)
dotnet add package tik4net            # low-level API only
dotnet add package tik4net.testing    # unit-testing support (TikFakeConnection)
dotnet add package tik4net.ssh        # SSH transport (4.x, alpha) — separate because of Renci.SshNet

Quick start — read the router identity

The simplest possible program: open a connection and print one value.

using tik4net;

using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
  connection.Open(HOST, USER, PASS);   // TikConnectionType.Api works for old and new (v6.43+) login
  ITikCommand cmd = connection.CreateCommand("/system/identity/print");
  Console.WriteLine(cmd.ExecuteScalar());
}

Read a list of typed entities (high-level API)

The recommended way to read/write data is the strongly-typed O/R mapper.

using tik4net;
using tik4net.Objects;

using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
  connection.Open(HOST, USER, PASS);
  foreach (var log in connection.LoadAll<Log>())
    Console.WriteLine("{0}[{1}]: {2}", log.Time, log.Topics, log.Message);
}

Create / update / delete (CRUD)

// Create an address-list item via the high-level API
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
  connection.Open(HOST, USER, PASS);
  var newAddressList = new FirewallAddressList()
  {
    Address = ipAddress,
    List = listName,
  };
  connection.Save(newAddressList);
  Console.WriteLine("Created item with id {0}", newAddressList.Id);
}

The same thing with the low-level and ADO.NET-like APIs, plus update/delete for all three levels, is on the CRUD examples for all APIs page.

Asynchronous / streaming commands (e.g. torch)

using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
  connection.Open(HOST, USER, PASS);
  var loadingContext = connection.LoadAsync<ToolTorch>(
    torchItem => Console.WriteLine(torchItem.ToString()),
    error => Console.WriteLine(error.ToString()),
    connection.CreateParameter("interface", interfaceName),
    connection.CreateParameter("port", "any"),
    connection.CreateParameter("src-address", "0.0.0.0/0"),
    connection.CreateParameter("dst-address", "0.0.0.0/0"));

  Console.ReadLine();
  loadingContext.Cancel();
}

Where to go next

Choosing the three API levels


Features

  • Easy to use — a few lines of code
  • R/W access and reading data
  • Support for parallel async commands (like torch)
  • ITikConnection as the single unified entry point to the router
  • Low-level API like other simple MikroTik API libraries
  • ADO.NET-like strongly-typed API (connection, commands, parameters)
  • High-level O/R-mapper-like API
    1. Strongly-typed objects for MikroTik entities (QueueTree, FirewallMangle, …)
    2. Support for ordering lists of entities on the router
    3. Support for merging collections with the state on the router (prepare the expected state, only the necessary operations are performed)
  • Unit-testing support via tik4net.testingTikFakeConnection tests all API levels without a live router
  • 🆕 4.x Change trackingSave diffs against the load-time snapshot and sends only changed fields; no-op saves skip the API call entirely
  • 🆕 4.x Safe ModeSafeModeTake() / SafeModeRelease() / SafeModeUnroll() with automatic rollback-on-disconnect (lockout protection)
  • 🆕 4.x MCP server — run any command over any transport from an AI assistant (Claude Code/Desktop), with per-transport RAW protocol trace
  • Clean design, clear, well-documented code

Connection transports

All transports sit behind the same ITikConnection interface — see connection types & capabilities for the full capability matrix, and how ExecuteXxx is translated per transport.

Transport Status
Api / ApiSsl — binary MikroTik API protocol (port 8728/8729) Stable
Rest / RestSsl — HTTP REST API (RouterOS 7.1+, port 80/443) 🆕 4.x · alpha preview
Telnet — plain-text CLI via TCP port 23 🆕 4.x · alpha preview
Ssh — encrypted CLI via an SSH shell, TCP 22 (separate tik4net.ssh package) 🆕 4.x · alpha preview
MacTelnet — Layer-2 CLI via UDP 20561 (no IP route needed, EC-SRP5 auth) 🆕 4.x · alpha preview
WinboxCli — encrypted CLI via the WinBox channel, TCP 8291 (EC-SRP5 + AES, no certificates) 🆕 4.x · alpha preview
WinboxCliMac — encrypted WinBox CLI over the MAC layer, UDP 20561 🆕 4.x · alpha preview
WinboxNative — structured CRUD via native WinBox M2 calls, TCP 8291 🆕 4.x · ⚠️ alpha preview
WinboxNativeMac — structured native WinBox M2 CRUD over the MAC layer, UDP 20561 🆕 4.x · ⚠️ alpha preview

Documentation

For the MikroTik protocol itself, see the MikroTik API manual.

Clone this wiki locally