tik4net 4.x is out — a big release for my API client for .NET. It still does what it always did: execution of parallel queries, easily handled thanks to an ADO.NET-like interface + O/R mapper-like extensions for a strong-typed experience (both single entity and lists of entities). What's new in 4.x is that it no longer talks only the native API — there are many new connection types (see below), all behind the same interface.
Please leave a message in this thread if you need some feature to be implemented or if you have any relevant question.
Repository: GitHub - danikf/tik4net: Manage mikrotik routers with .NET C# code via ADO.NET like API or enjoy O/R mapper like highlevel api. · GitHub
Wiki: Home · danikf/tik4net Wiki · GitHub
Getting started: Getting started · danikf/tik4net Wiki · GitHub
How to use: How to use tik4net library · danikf/tik4net Wiki · GitHub
Connection types & capabilities: Connection types and capabilities · danikf/tik4net Wiki · GitHub
Releases / version history: History · danikf/tik4net Wiki · GitHub
nuget package (recommended): https://www.nuget.org/packages/tik4net.entities/
Tested and debugged against RouterOS 7.21.4 (latest stable). Dlls target netstandard2.0, so tik4net runs on .NET Framework 4.6.1+, .NET Core 2.0+, .NET 5/6/7/8/9, Xamarin/Mono and Unity. Reference downloaded dlls only if you are not able to use the nuget package or the GitHub sources.
New in 4.x — many new connection types
All transports implement the same ITikConnection interface and the same O/R mapper (LoadAll<T>(), Save<T>(), …). You pick one via TikConnectionType and the rest of your code stays identical:
- Api / ApiSsl — native MikroTik API (TCP 8728 / TLS 8729); the default, fastest transport, full Listen/streaming
- Rest / RestSsl — REST API over HTTP/HTTPS (RouterOS 7.1+)
- Ssh — RouterOS CLI over an SSH shell (TCP 22); full CRUD + Listen + Safe Mode (satellite package
tik4net.ssh) - Telnet — RouterOS CLI over plain-text Telnet (TCP 23)
- MacTelnet — CLI over MAC-Telnet; reach a router with no IP configured / no IP route (Layer 2)
- WinboxCli / WinboxCliMac — CLI over the encrypted WinBox channel (TCP 8291 / MAC layer)
- WinboxNative / WinboxNativeMac — structured WinBox M2 binary CRUD, no terminal (TCP 8291 / MAC layer)
As far as I know, tik4net is the only .NET library that speaks MAC-Telnet and the WinBox protocols.
Features
ITikConnectionlow-level API (send command / read response, async commands)- ADO.NET-like API (
ITikCommand+ variousExecute…methods) - O/R mapper to/from entity classes (
connection.LoadList<T>()), now with a much larger set of built-in strong-typed entities - Change tracking — the entity layer tracks which properties you changed;
Save<T>()sends only the diff - Safe Mode across all transports (
TakeSafeMode()/ReleaseSafeMode()), with auto-rollback on disconnect - Streaming monitors — async/listen for live data (torch, log, …)
- Capability model — ask a connection what it supports:
connection.Supports(TikConnectionCapability.Listen) - Raw command pass-through —
ExecuteRawfor anything not covered by the mapper - C# entity code generators — semi-automatic generation of custom entities from a running MikroTik router and from the MikroTik wiki (official documentation)
- API-SSL support, plus the new MikroTik (from v6.43) login process
tik4net.testingpackage —TikFakeConnectionlets you write unit tests with no live router- MCP server — a
mikrotik_calltool that lets an AI assistant run commands against a live router over any tik4net transport
Examples
For read/write examples see the API comparison / CRUD examples wiki page: CRUD examples for all APIs · danikf/tik4net Wiki · GitHub
Read and print MikroTik router identity:
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
connection.Open(HOST, USER, PASS);
ITikCommand cmd = connection.CreateCommand("/system/identity/print");
Console.WriteLine(cmd.ExecuteScalar());
}
Same code over a different transport — just change the connection type (e.g. reach a router with no IP via MAC-Telnet):
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.MacTelnet))
{
connection.Open(MAC_ADDRESS, USER, PASS);
Console.WriteLine(connection.CreateCommand("/system/identity/print").ExecuteScalar());
}
Example of async Torch command:
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();
}
Read all log entries:
var logs = connection.LoadList<Log>();
foreach (Log log in logs)
{
Console.WriteLine("{0}[{1}]: {2}", log.Time, log.Topics, log.Message);
}
Firewall management:
//find first firewall rule
var firstFirewallRule = connection.LoadAll<FirewallFilter>().First();
// create new firewall rule as first rule in list
var firewallFilter = new FirewallFilter()
{
Chain = FirewallFilter.ChainType.Forward,
Action = FirewallFilter.ActionType.Accept,
};
connection.Save(firewallFilter);
connection.Move(firewallFilter, firstFirewallRule);
_NOTE: please do not use the deprecated 0.9.7 incompatible version of tik4net from https://code.google.com/p/mikrotik4net/._