Torch in c# API

Hello everyone.

I’m trying to use the API C #, specifically the command “torch” to see the consumption of bandwidth of a pppoe client in real time.

SSH CLI is “tool torch ”.


Via API’m trying to use as follows:

           mikrotik.Send ("/ tool / torch");
           mikrotik.Send ("= interface = <pppoe-blablabla>"); **(also ->)** mikrotik.Send ("= name = <pppoe-blablabla>")
           mikrotik.Send (, true "tag = sss.");

I do not know if the syntax is correct.

I am using the following api: http://wiki.mikrotik.com/wiki/API_in_C_Sharp

My need is this, I need my program show in real time the consumption TX and RX pppoe client. I’m using Windows Forms.

I tried to use a SSH libraries for C # but I can only successfully using Console Application, which is not what I need, but Windows Forms.

If anyone can help or exposing another solution, I thank now.

Thank you guys.

I’d highly recommend you get a more robust C# client, such as this one. With it, you should be able to more easily get the appropriate portions from the response.

With that in mind… your syntax with the current API client is mostly correct, except that you shouldn’t use spaces between tokens, and the tag, if you want it, starts with “.”, and the argument “true” is a separate one, i.e.

               mikrotik.Send ("/tool/torch");
               mikrotik.Send ("=interface=<pppoe-blablabla>");
               mikrotik.Send (".tag=sss", true);

boen_robot, thanks for the reply.

I’m sorry for the ignorance, but you could help me telling me how to run the torch command or a simple / log / print so I have an idea?
I’m getting to login quietly, but I can not and do not know how exactly do the syntax to execute commands with this new API and get the return command.
I’m confused. Sorry again for questioning basic things, you should be full of these questions here.

Thank you for your help.

You mean with that other API client?

I haven’t actually used it, but now, looking at the source in detail, the following would do “/log/getall” (which should be equivalent to “/log/print”), and print out each line of the log as a line in the console.

Connection conn = new Connection("192.168.88.1", "admin", "password");
Response items = conn.ExecuteCommand(new GetAllCommand("log"));
foreach (Record item in items) {
    System.Console.WriteLine("{0} : {1}", item["topics"], item["message"]);
}

(This is actually a little… let’s say “different”… than what my previous inspections have suggested, but it still beats the API client in the wiki)

mk.JPG
I’ll tell you what I’m trying to do. I’m developing my college project on a tool in C # that works with mikrotik. Several commands I can run over SSH without problems, and with the response usually using a SharpSSH library.
But, I need a solution for bandwidth consumption in real time, either by Torch, or queue, whatever.
The problem is that in SSH using the library for C #, I just get an answer and the session ends, if you want again, start another session and thus generates much logging and processing greatly increases the RouterBoard.
Using the first API that I quoted (http://wiki.mikrotik.com/wiki/API_in_C_Sharp), can the real-time response but only via Console Application, and would result in a TextBox, via Windows Forms.
Via Windows Forms have to log in several times, causing extensive log and consumption of execessivo RouterBoard cpu.
If you have any solution, I will be eternally grateful.

ps: I’m using the library mentioned by you boen_robot :slight_smile: (https://bitbucket.org/ayufan/rosapi-csharp/src/19eb7f1059933a6407286d86bf55b49848b6b5fa/RouterOS.API/?at=master)

ps²: I’m not a professional, and I know little of C #, so the basic questions and perhaps boring for you, excuse me.

ps³: Attached a printscreen this your code. Here consists error

Many thanks for the help!

I’m assuming this is from inside Visual Studio… You should be able to right click on GetAllCommand, and select… If I remember correctly, something like “Resolve namespace” or something of that sort… And then select “RouterOS.API.GetAllCommand”.

Or alternatively, you can manually add

use RouterOS.API.GetAllCommand;

Above your class declaration (you know, alongside the rest of the “use” statements).

Once you get the console working successfully, migrating to a WindowsForms application is as simple as putting that same code inside the appropriate event, and replacing “System.Console.WriteLine” with whatever form control’s content you want modified.

The problem is that in SSH using the library for C #, I just get an answer and the session ends, if you want again, start another session and thus generates much logging and processing greatly increases the RouterBoard.

Technically, with both SSH and the API, and with both Console and Windows Forms, it’s up to you to command when you log in and log out. While you are not logged out, you can issue new commands and get their output. As long as the variable holding the TCP connection (in the case above, “conn”) is alive, the connection is alive, and you don’t need to log in again.

can the real-time response but only via Console Application, and would result in a TextBox, via Windows Forms.

You can always append data to a text box, rather than replacing it. This would be one way to see the data over time.

Better yet, you could use a more appropriate control, in which you can add multiple data points. In the case of CPU or queue measurements, a graphing utility, such as the built in Chart control (for .NET 4.5 and later) or this library would be most appropriate… But admittedly, more difficult to learn.