I have just published my API client for .NET. It implements execution of parallel queries which are easily handled due to ADO.NET-like interface + O/R mapper like extensions to provide strong-typed experience (it supports both single entity and list of entities).
Please leave message in this thread if you need some feature to be implemented or if you have any relevant question.
Repository: https://github.com/danikf/tik4net
Wiki: https://github.com/danikf/tik4net/wiki
How to use: https://github.com/danikf/tik4net/wiki/How-to-use-tik4net-library
nuget package: https://www.nuget.org/packages/tik4net/
Releases (usage of nuget package is recommended):
tik4net-3.5.0.zip (1.72 MB)
tik4net-3.4.0.zip (1.44 MB)
Features:
- ITikConnection lowlevel API (send command / read response, async commands)
- ADO.NET like api (ITikCommand + various Execute… methods)
- O/R mapper to/from entity classes. (connection.LoadList())
- Release also contains C# entity code generators to support semi-automatic generation of custom entities from running mikrotik router and from mikrotik wiki site (from oficial documentation)
- API-SSL > support
- New mikrotik (from v. 6.43) login process support
- Dlls builded for .NET 3.5, 4.0, 4.5.x, 4.6.x, netcoreapp1.1, netcoreapp2.0, netstandart1.3, netstandard1.4, netstandard1.6
- Functional with xamarin and other .NET runtimes based on Mono
Reference downloaded dlls only if you are not able to use > nuget package > or > GitHub sources.
Examples
For read/write examples see API comparison CRUD examples wiki page.
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());
}
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 deprecated 0.9.7 incompatible version of tik4net from https://code.google.com/p/mikrotik4net/._
tik4net-3.3.0.zip (1.42 MB)