Repository navigation
From the console to tik4net
Daniel Frantík edited this page Nov 27, 2026
·
4 revisions
You know the RouterOS console. This page maps what you type there to the two calls you would write instead: the O/R mapper (typed entities) and the ADO.NET-like API (commands and parameters). Both run on every transport.
using tik4net;
using tik4net.Objects;
using tik4net.Objects.Ip;
var setup = new TikConnectionSetup("192.168.88.1", "admin", "");
using (ITikConnection connection = setup.Create(TikConnectionType.Api))
{
// /ip address print where interface=ether1
foreach (var address in connection.LoadList<IpAddress>(connection.CreateParameter("interface", "ether1")))
Console.WriteLine(address.Address);
}The path is the API spelling (/ip/address, slashes, no spaces); the menu's entity class is on
Entity reference.
| You type | O/R mapper | Command |
|---|---|---|
/ip address print |
connection.LoadAll<IpAddress>() |
connection.CreateCommand("/ip/address/print").ExecuteList() |
/ip address print where interface=ether1 |
connection.LoadList<IpAddress>(connection.CreateParameter("interface", "ether1")) |
connection.CreateCommandAndParameters("/ip/address/print", "interface", "ether1").ExecuteList() |
/ip address print detail |
LoadAll — an entity that needs detail asks for it itself |
CreateParameter("detail", "", TikCommandParameterFormat.NameValue) |
/interface print where name=ether1 (one row) |
connection.LoadByName<Interface>("ether1"), or LoadSingle<T>(filter)
|
….ExecuteSingleRow() |
/system identity print (a singleton) |
connection.LoadSingle<SystemIdentity>() |
connection.CreateCommand("/system/identity/print").ExecuteSingleRow() |
:put [/system identity get name] |
connection.LoadSingle<SystemIdentity>().Name |
connection.CreateCommand("/system/identity/print").ExecuteScalar("name") |
/ip address add address=10.0.0.1/24 interface=ether1 |
connection.Save(new IpAddress { Address = "10.0.0.1/24", Interface = "ether1" }) — fills Id
|
connection.CreateCommandAndParameters("/ip/address/add", "address", "10.0.0.1/24", "interface", "ether1").ExecuteScalar() — returns the .id
|
/ip address set [find address="10.0.0.1/24"] comment=lan |
load it, address.Comment = "lan", connection.Save(address) — sends only comment
|
CreateCommandAndParameters("/ip/address/set", ".id", id, "comment", "lan").ExecuteNonQuery() |
/ip address unset [find …] comment |
address.Comment = null, connection.Save(address)
|
CreateCommandAndParameters("/ip/address/unset", ".id", id, "value-name", "comment").ExecuteNonQuery() |
/ip address remove [find …] |
connection.Delete(address), or connection.DeleteById<IpAddress>(id) with only the .id
|
CreateCommandAndParameters("/ip/address/remove", ".id", id).ExecuteNonQuery() |
/ip address disable [find …] / enable
|
address.Disabled = true (or false), connection.Save(address)
|
CreateCommandAndParameters("/ip/address/disable", ".id", id).ExecuteNonQuery() |
/ip firewall filter move 3 destination=1 |
connection.Move(rule, ruleBefore), connection.MoveToEnd(rule)
|
CreateCommandAndParameters("/ip/firewall/filter/move", "numbers", id, "destination", beforeId).ExecuteNonQuery() |
/ip firewall address-list remove [find list=blocked] |
LoadList with the filter, then Delete each |
print with the filter, then remove each .id
|
/interface monitor-traffic ether1 once |
connection.GetInterfaceMonitorTrafficSnapshot("ether1") |
— |
/ping 10.0.0.1 count=4 |
connection.Ping("10.0.0.1", 4) |
— |
/tool torch ether1 (runs until Ctrl+C) |
LoadWithCallbackAsync<ToolTorch>(…, token), stopped by cancelling the token |
ExecuteWithCallbackAsync(…, token), stopped by cancelling the token |
/ip address listen |
LoadListenWithCallbackAsync<IpAddress>(…) |
/ip/address/listen with ExecuteWithCallbackAsync
|
/export, :foreach …, any script |
— | the line itself, on a CLI transport: cli.CreateRawCommand("/export").ExecuteScalar()
|
-
[find …]is a load. The console'sfindselects rows by any condition; tik4net reads them with a filter and then writes each one by its.id. A filter is an exact match on one field per parameter, several parameters meaning and — the full query language is on Low-level API. -
A value in the console's spelling (
1d,!22,8291,syn,!ack) goes into any typed property throughTik.Wire:server.LeaseTime = Tik.Wire("1d"),rule.DstPort = Tik.Wire("!22,8291"). It is parsed for that property and refused if the type cannot hold it — see TikField. -
A row number (
set 3) is the console's own; it does not exist outside oneprint. tik4net always addresses a row by its.id. - Scripting and free text need the console's own language: CLI raw commands.
using tik4net;
using tik4net.Objects;
using tik4net.Objects.Ip.Firewall;
// /ip firewall address-list add list=blocked address=10.20.30.40 comment="tik4net"
var entry = new FirewallAddressList { List = "blocked", Address = "10.20.30.40", Comment = "tik4net" };
connection.Save(entry);
// /ip firewall address-list set [find list=blocked address=10.20.30.40] timeout=1d
entry.Timeout = Tik.Wire("1d");
connection.Save(entry);
// /ip firewall address-list remove [find list=blocked address=10.20.30.40]
connection.Delete(entry);
// the same three at the command level
string id = connection.CreateCommandAndParameters("/ip/firewall/address-list/add",
"list", "blocked", "address", "10.20.30.40", "comment", "tik4net").ExecuteScalar();
connection.CreateCommandAndParameters("/ip/firewall/address-list/set", ".id", id, "timeout", "1d").ExecuteNonQuery();
connection.CreateCommandAndParameters("/ip/firewall/address-list/remove", ".id", id).ExecuteNonQuery();- Getting started — the first project
- Reading data · Create, update, delete
- ADO.NET-like API — commands, parameters, filter vs. name-value
- CLI raw commands — the console's own syntax, sent unchanged
Start
- Getting started — first project
- From the console to tik4net — what you type, what you call
- Building an application — a service, reconnecting, logging
- Library overview
- CRUD at all three levels
- One task, every transport
Connecting
- Connecting to a router — setup, options, connection string
- Transports & capabilities — the matrix
- Threading & concurrency
- API · API-SSL
- REST
-
CLI transports
- Telnet · SSH · WinBox CLI
- MAC-layer transports — no IP needed
- WinBox native · GUI-like syntax
- RoMON — through a neighbouring router
- MNDP discovery
Working with data
- Low-level API — raw sentences
- ADO.NET-like API — commands, parameters
- CLI raw commands · tips & tricks
- Command translation
- Async & cancellation
- Monitors & streaming — ping, torch, listen
O/R mapper
-
High-level API
- Reading data · Create, update, delete
- Change tracking · List merge
- TikField · Value lists & negated matchers · Value types · Helpers
- Entity reference — every covered menu
- Custom entities
Safety
- Safe Mode — rollback protection
- Exception handling
RouterOS
Testing & diagnostics
Extending & tools
Project