Repository navigation
WinBox Native GUI syntax
Experimental. WinBox native is the experimental transport of 4.0, and addressing it by GUI names is the newest part of it. For production work over the WinBox channel use WinBox CLI, which can also take raw CLI commands.
tik4net lets you address a WinBox native connection in either of two dialects:
-
the API dialect, translated for you —
/ip/firewall/filter/print,src-address. This is the standard way, portable across all eleven transports, and the one the O/R mapper uses. How the names are mapped is described on WinBox native connection. -
WinBox's own names —
/IP/Firewall/Firewall Rule,Src. Address: the menu, the window and the field caption, as the WinBox screen shows them. This page is about this one.
This is the WinBox counterpart of CLI raw commands, with one difference you need to know up front: WinBox has no command language. A CLI raw command is a line of text sent unchanged; WinBox speaks numbered binary messages, so there is no text to send unchanged. Its native names are what you can write, and tik4net still resolves them to numbers for you.
WinBox does not know RouterOS menus the way the CLI and the API do. It draws a tree of windows that the
router itself describes, in a catalog file it serves for its own version (roteros.jg and friends,
fetched once per connection and cached). A trimmed piece of it:
{name:'Firewall Rule', title:'Filter Rules', type:'map', path:[ 20,3 ], c:[
{name:'Chain', type:'string', id:'s14'},
{name:'Action', type:'enm', id:'u13'},
... ]}Read top-down, that is the whole addressing model:
flowchart LR
menu["<b>menu</b><br/>IP ▸ Firewall"] --> win["<b>window</b> Firewall Rule<br/>list caption: Filter Rules<br/><i>path:[20,3]</i>"]
win --> f1["<b>field</b> Chain<br/><i>id:'s14'</i>"]
win --> f2["<b>field</b> Action<br/><i>id:'u13'</i>"]
win --> f3["<b>field</b> Src. Address<br/><i>type:'opt'</i>"]
- A menu is what you click through in WinBox's left bar. It has no number of its own.
- A window is one table (or one settings form). It has two labels: its
name— Firewall Rule, the caption of the dialog that opens on a row — and itstitle— Filter Rules, the caption of the list. Itspath:[major,minor]is the handler the M2 message is sent to. The numbers move between RouterOS versions; the labels do not. - A field is a caption in that window. Its
idis a type letter (sstring,unumber,bflag, …) followed by the numeric key the value travels under —s14is the string under key0x14. - A request on the wire is therefore handler + command + key/value pairs —
[20,3], "get all",0x…— with no text anywhere.
So the names WinBox gives you are the menu breadcrumb, the window's name and the field caption. They are
English labels written for people, not identifiers: Firewall Rule rather than filter, Resources
rather than resource, Src. Address with a dot and a space. That is why GUI-like syntax looks like
/IP/Firewall/Firewall Rule — it is a path through that tree, and tik4net walks the router's own catalog to
turn it into the handler and keys.
using var conn = setup.CreateWinboxNativeConnection(c => c.UseGuiNames = true);UseGuiNames folds case, turns spaces and _ into - and drops abbreviation dots, then resolves the result
against the router's catalog. A name that already resolves as an API name is used as it is, so turning the
flag on never changes the meaning of code that uses API names. Rows always come back with API field
names (src-address), whichever way you addressed the request.
UseGuiNames is not a connect-time setting: the resolvers are built per operation and read the flag when
the command executes, so it can be scoped to a single call and the rest of the session kept strict:
using var conn = setup.CreateWinboxNativeConnection(); // strict API names by default
conn.UseGuiNames = true; // ← labels accepted from here on
conn.CreateCommandAndParameters("/IP/Firewall/Firewall Rule/set", ".id", id, "Src. Address", "10.0.0.0/24")
.ExecuteNonQuery();
conn.UseGuiNames = false; // ← back to strictIt is mutable connection state: don't toggle it while the same connection is in use from another thread — set it once before first use instead.
Measured on RouterOS 7.24.5. A path that does not resolve throws TikPathNotMappedException before
anything is sent.
| You write | Resolves to | |
|---|---|---|
/IP/Firewall/Filter |
/ip/firewall/filter |
the API path, any case |
/IP/Firewall/Firewall Rule |
/ip/firewall/filter |
menu + the window's name |
/IP/Firewall/Address List |
/ip/firewall/address-list |
|
/IP/DNS/DNS Static Entry |
/ip/dns/static |
|
/System/Resources/Resources |
/system/resource |
the window is named Resources too |
/IP/Addresses/Address |
/ip/address |
|
/Interfaces/Interface |
/interface |
|
/IP/Firewall/Address Lists |
— | the list's caption, not the window's name |
/IP/Firewall/Filter Rules |
— | the same |
/System/Resources |
— | a menu without its window |
/PPP/PPP Secret |
/ppp/secret |
the window sits directly under the PPP menu |
/PPP/Secrets/PPP Secret |
— | Secrets is the list's caption, not a level of the tree |
The rule of thumb: menu breadcrumb, then the window's name — the caption of the dialog that opens when you double-click a row, not the caption of the list or tab you clicked to get there.
When an API path has no window of the same name, teach the connection which window it means — by its
labels, before Open:
using var conn = setup.CreateWinboxNativeConnection(c =>
{
// WinBox tree: PPP ▸ (window) PPP Secret
c.PathAlias("/ppp/secret", "/ppp/ppp-secret");
});An alias pins only text, so it keeps working after a RouterOS upgrade renumbers the handler. The numeric
escape hatches (PathOverride, FieldOverride) pin the numbers themselves and are described on
WinBox native connection.
The program reads two windows by the names on the WinBox screen and changes one field by its caption — the kind of code you write while looking at WinBox.
// ==========================================================================
// TASK read System ▸ Resources and the firewall rule list by their WinBox names,
// then write a field of one rule by its caption
// LEVEL ADO.NET-like, addressed with WinBox GUI names (UseGuiNames)
// TRANSPORT WinboxNative — structured WinBox M2, TCP 8291 (experimental)
// ==========================================================================
// ON THE ROUTER: the winbox service, and a user with read,write plus the 'winbox' policy.
// Step 3 changes the comment of the rule commented "managed-by-tik4net", if one exists.
// ==========================================================================
using System;
using System.Linq;
using tik4net;
using tik4net.WinboxNative;
class Program
{
const string Host = "192.168.88.1";
const string User = "admin";
const string Password = "";
static void Main()
{
var setup = new TikConnectionSetup(Host, User, Password);
using (ITikWinboxNativeConnection conn = setup.CreateWinboxNativeConnection(c => c.UseGuiNames = true))
{
// 1. System ▸ Resources — the window is named "Resources" as well.
var res = conn.CreateCommand("/System/Resources/Resources/print").ExecuteSingleRow();
Console.WriteLine("cpu-load " + res.GetResponseField("cpu-load") + " %, free memory "
+ res.GetResponseField("free-memory")); // ← API names on output
// 2. IP ▸ Firewall ▸ Filter Rules — rows of the window "Firewall Rule".
var rules = conn.CreateCommand("/IP/Firewall/Firewall Rule/print").ExecuteList().ToList();
foreach (var rule in rules)
Console.WriteLine(rule.GetId() + " " + rule.GetResponseFieldOrDefault("chain", "?")
+ " → " + rule.GetResponseFieldOrDefault("action", "?"));
// 3. Write by caption. The row is chosen client-side: a native read reads the whole
// window anyway, so nothing is lost by filtering here.
var marked = rules.FirstOrDefault(r => r.GetResponseFieldOrDefault("comment", null) == "managed-by-tik4net");
if (marked != null)
conn.CreateCommandAndParameters("/IP/Firewall/Firewall Rule/set",
".id", marked.GetId(),
"Comment", "managed-by-tik4net (seen)")
.ExecuteNonQuery();
}
}
}- Names in, API names out. GUI names are accepted on input only.
-
A caption is folded, not looked up. The flag only folds separators and case, so a caption that does
not reduce to its API name that way — Tx for
tx-byte— needs a built-in alias or aFieldOverride. -
Not a raw level.
CreateRawCommandandCallCommandSyncdo not exist on WinBox native (it does not reportRawCommand): there is no text to pass through. For a command the native mapping does not cover, open WinBox CLI on the same port and use CLI raw commands.
- WinBox native connection — the transport, its coverage and every mapping hook
- CLI raw commands — native syntax on the CLI transports
- Command translation on non-API transports — the API dialect on every transport
-
Communication debugging — the
wbx.*trace channels show the handler and keys each request used
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