-
Notifications
You must be signed in to change notification settings - Fork 98
Home
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.xline. Items tagged4.xbelow are on the4.xdevelopment 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.
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
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());
}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 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.
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();
}- New here? How to use tik4net — picks the right API level for you.
- CRUD examples for all APIs — the same operations across all three API levels.
- High-level API with O/R mapper (recommended) — strongly-typed entities.
- ADO.NET-like API — commands, parameters, scalars/lists.
- Low-level API — raw sentences, like other MikroTik libraries.
- VisualBasic example · Exception handling · History / changelog
- 4.x Roadmap — what's coming in the next major version.
- Low-level API — send raw API sentences and read raw responses.
-
ADO.NET-like API — strongly-typed
ITikConnection/ITikCommand/ITikCommandParameter. - High-level O/R mapper — typed entities (QueueTree, FirewallFilter, …) with full CRUD.
- Easy to use — a few lines of code
- R/W access and reading data
- Support for parallel async commands (like torch)
-
ITikConnectionas 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
- Strongly-typed objects for MikroTik entities (QueueTree, FirewallMangle, …)
- Support for ordering lists of entities on the router
- 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.testing—TikFakeConnectiontests all API levels without a live router - 🆕
4.xChange tracking —Savediffs against the load-time snapshot and sends only changed fields; no-op saves skip the API call entirely - 🆕
4.xSafe Mode —SafeModeTake()/SafeModeRelease()/SafeModeUnroll()with automatic rollback-on-disconnect (lockout protection) - 🆕
4.xMCP 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
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 · |
WinboxNativeMac — structured native WinBox M2 CRUD over the MAC layer, UDP 20561 |
🆕 4.x · |
- How to use tik4net
- CRUD examples for all APIs
- Exception handling — error handling and the full exception tree
- VisualBasic trivial example
- History / changelog
- 4.x Roadmap
For the MikroTik protocol itself, see the MikroTik API manual.