Home
Softono
tik4net

tik4net

Open source Apache-2.0 C#
191
Stars
98
Forks
15
Issues
42
Watchers
3 weeks
Last Commit

About tik4net

tik4net is a .NET library for managing MikroTik routers through the MikroTik API protocol. It provides a clean, scalable interface ranging from low-level raw API access to a fully typed O/R mapper for high-level operations. The library ships as three NuGet packages. The core tik4net package offers synchronous and asynchronous read/write access through an ADO.NET-like API. tik4net.entities builds on this with a high-level O/R mapper featuring strongly typed entities and full CRUD operations. tik4net.testing provides TikFakeConnection for unit testing without a live router. Key features include both low-level API access and an easy-to-use O/R mapper, stable interfaces with backward compatibility, support for a broad range of .NET runtimes including .NET Framework 4.6.1+, .NET Core 2.0+, .NET 5 through 9, Xamarin, and Unity, compatibility with the modern RouterOS login process, and an MNDP discovery helper. The current release targets netstandard2.0 and is tested against RouterOS 7.21.4. The library is well-docu

Platforms

Web Self-hosted Windows

Languages

C#

Links

tik4net

📢 A note from the maintainer

Version 3.6.0 is out! Thanks to AI tooling I finally had the bandwidth to work through all open PRs and critical bugs. Special thanks to Deantwo and all contributors who helped others while I was away.

I am looking for collaborators. If you are interested in helping maintain this project, please reach out — open an issue or contact me directly.

Current release targets netstandard2.0 only. This covers .NET Framework 4.6.1+, .NET Core 2.0+, .NET 5/6/7/8/9, Xamarin, and Unity.

Tested and debugged against RouterOS 7.21.4 (latest stable).

tik4net is a .NET library for communicating with MikroTik routers via the MikroTik API protocol. It offers a clean, easy-to-use interface that scales from low-level raw API access all the way up to a fully typed O/R mapper.

Package NuGet Description
tik4net NuGet Low-level ADO.NET-like API — synchronous and async R/W access
tik4net.entities NuGet High-level O/R mapper — strongly typed entities, full CRUD. Pulls in tik4net automatically.
tik4net.testing NuGet Unit-testing support — TikFakeConnection lets you write tests without a live router

Tools — semi-automatic C# code generators for custom entities (used with tik4net.entities).

Features

  • Easy to use with O/R mapper like highlevel API
  • Low level access supported by low level API
  • Stable interface and backward compatibility
  • Broad range of .NET runtimes supported (including .NET core 2 and Xamarin)
  • New mikrotik v.6.43 login process supported
  • Includes MNDP discovery helper
  • Easy to understand and well documented code

Binaries

Install via NuGet — see the package table above, or:

dotnet add package tik4net.entities  # high-level API (pulls in tik4net)
dotnet add package tik4net           # low-level API only
dotnet add package tik4net.testing   # unit-testing support

See release notes / version history for what's new.

Getting started and documentation

Mikrotik API wiki:

Project wiki:

Examples:

   using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api_v2)) // Use TikConnectionType.Api for mikrotikversion prior v6.45
   {
      connection.Open(HOST, USER, PASS);
   ITikCommand cmd = connection.CreateCommand("/system/identity/print");
   var identity = cmd.ExecuteScalar(); 
   Console.WriteLine("Identity: {0}", identity);
   var logs = connection.LoadList<Log>();
   foreach (Log log in logs)
   {
       Console.WriteLine("{0}[{1}]: {2}", log.Time, log.Topics, log.Message);
   }
   var firewallFilter = new FirewallFilter()
   {
      Chain = FirewallFilter.ChainType.Forward,
      Action = FirewallFilter.ActionType.Accept,
   };
   connection.Save(firewallFilter);
   ITikCommand torchCmd = connection.CreateCommand("/tool/torch", 
      connection.CreateParameter("interface", "ether1"), 
      connection.CreateParameter("port", "any"),
      connection.CreateParameter("src-address", "0.0.0.0/0"),
      connection.CreateParameter("dst-address", "0.0.0.0/0"));

  torchCmd.ExecuteAsync(response =>
      {
         Console.WriteLine("Row: " + response.GetResponseField("tx"));
      });
  Console.WriteLine("Press ENTER");
  Console.ReadLine();
  torchCmd.Cancel();

Looking for help

  • Importing other classes
  • Looking for betatesters

Roadmap & future

  • create highlevel classes for all mikrotik entities (you can still generate your own classes)
  • create tiklink project - easy use-to wrapper over mikrotik router with fluent API
  • convert examples to separate unittests (in progress)
  • tiktop — a MikroTik traffic monitor inspired by Linux iftop (currently in alpha, available on NuGet/GitHub)

REMARKS: This project is rewritten version of deprecated tik4net at googlecode (last version was 0.9.7.)

Licenses

  • Apache 2.0.