Skip to content

How to use tik4net library

Daniel Frantik edited this page Mar 5, 2016 · 21 revisions

The main entry point is mikrotik router connection object (ITikConnection). Instance of connection object should be instancied via factory (ConnectionFactory).

using tik4net;
// ...
connection = ConnectionFactory.OpenConnection(TikConnectionType.Api, HOST, USER, PASS);

When using tik4Net library, you should consider which API you would like to use:

##Low-level API

  • Low-level API: first option is to use low-level API like other mikrotik libraries do. It allows you to send API commands to mikrotik router and read response to these command.
// expectes opened connection - see example above
string[] command = new string[] { "/interface/print" };
IEnumerable<ITikSentence> result = Connection.CallCommandSync(command);
// returns list of respose sentences

##ADO.NET like API

  • ADO.NET like API: second option is to use ADO.NET like API. This API tries to be very simmilar to database API used in .NET world. It allows you to create ITikCommand commands, use parameters and other features like ADO.NET does.
// expectes opened connection - see example above
ITikCommand cmd = connection.CreateCommand("/system/identity/print");
string identity = cmd.ExecuteScalar();
Console.WriteLine("Identity: " + identity);

##High-level API with O/R mapper

Clone this wiki locally