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/ ... et-library
nuget package:https://www.nuget.org/packages/tik4net/
Releases (我们age of nuget package is recommended):
ExamplesFeatures:Reference downloaded dlls only if you are not able to usenuget packageorGitHub sources.
- 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-SSLsupport
- 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
For read/write examples seeAPI comparison CRUD exampleswiki page.
Read and print mikrotik router identity
使用(= ConnectionFacto ITikConnection连接ry.CreateConnection(TikConnectionType.Api)) { connection.Open(HOST, USER, PASS); ITikCommand cmd = connection.CreateCommand("/system/identity/print"); Console.WriteLine(cmd.ExecuteScalar()); }
使用(= ConnectionFacto ITikConnection连接ry.CreateConnection(TikConnectionType.Api)) { connection.Open(HOST, USER, PASS); var loadingContext = connection.LoadAsync( 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(); }
var logs = connection.LoadList(); foreach (Log log in logs) { Console.WriteLine("{0}[{1}]: {2}", log.Time, log.Topics, log.Message); }
//find first firewall rule var firstFirewallRule = connection.LoadAll().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);