Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get id of any object #95

Open
Shepard199 opened this issue Jan 12, 2024 · 1 comment
Open

Get id of any object #95

Shepard199 opened this issue Jan 12, 2024 · 1 comment

Comments

@Shepard199
Copy link

Shepard199 commented Jan 12, 2024

Hi, help me, please.For example, when I try to get the ID of any interface, I get an obscure id - (I get id - *83F, but the real id is 1198). Or how should I properly delete the interface I need?

@Deantwo
Copy link
Contributor

Deantwo commented Mar 5, 2024

The intern IDs in RouterOS are all *83F or similar. You can see the same if you do :put [/interface find] on the router's terminal.

Example code:

TikConnection con = ConnectionFactory.OpenConnection(Type.Api, _host, _username, _password);

ITikCommand cmd = conn.CreateCommand("/interface/print", conn.CreateParameter("name", _ifName));
string id = cmd.ExecuteScalar(".id");
System.Diagnostics.Debug.WriteLine($"Interface ({_ifName}) ID: {id}");

cmd = conn.CreateCommand("/interface/remove", conn.CreateParameter(".id", id));
cmd.ExecuteNonQuery();
System.Diagnostics.Debug.WriteLine($"Interface ({_ifName}) deleted");

But since interfaces are objects with identifier names, you can delete them directly without getting the ID, like this:

TikConnection con = ConnectionFactory.OpenConnection(Type.Api, _host, _username, _password);

cmd = conn.CreateCommand("/interface/remove", conn.CreateParameter(".id", _ifName));
cmd.ExecuteNonQuery();
System.Diagnostics.Debug.WriteLine($"Interface ({_ifName}) deleted");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants