Community discussions

 
kristaps
Member Candidate
Member Candidate
Posts: 272
Joined: Mon Jan 27, 2014 1:37 pm

Re: C# API - tik4net on GitHub

Fri Jul 08, 2016 7:30 pm

We will fix attachment issue. 

Thanks for this API, Keep the good work. 
 
santolag
just joined
Posts: 2
Joined: Thu Jul 21, 2016 8:57 am

Re: C# API - tik4net on GitHub

Wed Jul 27, 2016 8:42 am

Hi,

Great codes,
I'm just here to learn a lot about API via C#
I'm currently trying about PPPoE and stuffs at Firewall,
Any suggestion where to start the code or tricks?

Thanks,
Martin
 
klhsu
just joined
Posts: 1
Joined: Wed Nov 30, 2016 5:25 pm

Re: C# API - tik4net on GitHub

Wed Nov 30, 2016 6:03 pm

Hi danikf

At first I like to say thank you for developed this good api for managing routerOS very easily.
I have an issue as following, hope you can help me how to do.

I've created some accounts for VPN user accounts,I write some code for a function to disable ppp user account, I have test in terminal console in my routerOS as
ppp secret set [find name=username] disable=yes
It works fine after command executed in terminal console.

my c# code with tik4net command as bellow:
ITikCommand cmd = connection.CreateCommandAndParameters("/ppp/secret/set find[name=" + username + "] disable=yes"); 
cmd.ExecuteNonQuery();
the username is a variable for ppp user name that I want to disable with.

but the message be shown after execute command : no such command.

Do you have any idea to tell how to perform the command by CreateCommand() method ?

I really appreciate your instructions.

Albert Hsu
 
nescafe2002
Member
Member
Posts: 489
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: C# API - tik4net on GitHub

Wed Nov 30, 2016 9:53 pm

API supports query operator only in print command.

http://wiki.mikrotik.com/wiki/Manual:API#Query_word

You could split the getting and setting of secret, e.g.:
// Retrieve the secret.
ITikReSentence secret = conn.CreateCommandAndParameters("/ppp/secret/print", "name", username).ExecuteSingleRow();

// Disable the secret.
conn.CreateCommandAndParameters("/ppp/secret/set", ".id", secret.Words[".id"], "disabled", "true").ExecuteNonQuery();
For multiple secrets:
// Retrieve pptp secrets.
IEnumerable<ITikReSentence> secrets = conn.CreateCommandAndParameters("/ppp/secret/print", "service", "pptp").ExecuteList();

foreach (var secret in secrets)
{
  // Disable the secret.
  conn.CreateCommandAndParameters("/ppp/secret/set", ".id", secret.Words[".id"], "disabled", "true").ExecuteNonQuery();
}
Note that this way your parameter values are separated from the actual commands, which will lead to a more secure application (less vulnerable to command injection).
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sun Dec 11, 2016 8:02 pm

Hi all,
just created wiki example page for all CRUD scenarios for all APIs.

https://github.com/danikf/tik4net/wiki/ ... r-all-APIs

In hope you can see the flexibility of higlevel API,
D

BTW: thanks nescafe2002 for supporting other users :-)
 
anishpsla
newbie
Posts: 30
Joined: Mon Aug 25, 2014 9:16 am

Re: C# API - tik4net on GitHub

Wed Jan 18, 2017 6:39 pm

Any information of adding .net core support ?
 
mveselic
just joined
Posts: 1
Joined: Sun Jan 29, 2017 9:14 am

Re: C# API - tik4net on GitHub

Sun Jan 29, 2017 9:17 am

is it possible to send sms messages via this API?
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sun Feb 05, 2017 3:55 pm

Hi,
probably yes - in general. You can perform every operation which you can script in mikrotik API :-) I don't have GSM modem connected to mikrotik so I can't test it.

The code could be (not tested):
ITikCommand smsCmd = connection.CreateCommand("/tool/sms/send", 
    connection.CreateParameter("port", "usb3"), 
    connection.CreateParameter("channel", "3"), 
    connection.CreateParameter("phone-number", "00420777123456"), // or "dst" instead of "phone-number" - depends on tik version ???
    connection.CreateParameter("message", "Test message.")    
);
smsCmd.ExecuteNonQuery();
SMS documentation (warning - it is documentation for console, not for API - syntax will be a little bit different):
http://wiki.mikrotik.com/wiki/Manual:Tools/Sms

Other usefull links:
https://aacable.wordpress.com/2012/11/2 ... gsm-modem/
http://forum.mikrotik.com/viewtopic.php ... it=sms+api


Remarks: you have to install advanced-tools package and have gsm modem connected to mikrotik.

Let me know if it works,
D
 
MarkLFT
just joined
Posts: 14
Joined: Mon Apr 23, 2012 7:22 am

Re: C# API - tik4net on GitHub

Tue Feb 28, 2017 6:23 am

I have come across a problem, and would like some advice. We have been using this API for a while, and it is very useful. The problem I have is when we create hotspot users, some of the users names or passwords include non Latin characters, i.e. umlauts etc. Our software stores these names correctly, but when we try to send the name to the router, it seems to arrive as a /?

How can we send the correct characters to the router? As a number of users complain the hotspot is not working, but actually it is because their name contains non-Latin characters.

Many thanks, and keep up the good work.
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Tue Feb 28, 2017 2:36 pm

Hi,
take a look at connection.Encoding parameter of connection.

See https://github.com/danikf/tik4net/wiki/ ... characters for details.

D
 
lucianozem
just joined
Posts: 2
Joined: Wed Mar 08, 2017 3:32 pm

Re: C# API - tik4net on GitHub

Wed Mar 08, 2017 4:06 pm

Hi danikf,

I wold like to verify the traffic packets in the router, more specifically the RTP protocol. Can i do this?
and the another question, can i connect two routers in same time?
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Fri Mar 10, 2017 12:31 pm

Hi,

RTP is usualy based on UDP - so you can monitor the traffic (see tik4net.torch example project: https://github.com/danikf/tik4net/tree/ ... 4net.torch). If you want to examine every packet (sniffer?), may be you can use sniffer feature, but it will be IMHO very bad idea. It will be better to use mikrotik sniffer streaming feature (without API). Basically - you can do every operation with this API which you can perform via pure API calls :-)

To connect two routers at the same time just create two ITikConnection connections.

D
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sat Apr 01, 2017 4:21 pm

Hi,

just published new version 2.2.0.0 of tik4net library.

Whats new:
* API update to meet CRUD examples
* multiline response (script) fix. Credits: pmishka
* Adding CapsManRegistrationTable entity and support TimeSpan convertion. Credits: sebastienwarin

Updates for .NET Core will be (hopefully) in the next release.

Enjoy,
D
 
Centauri
Frequent Visitor
Frequent Visitor
Posts: 50
Joined: Sun Jun 06, 2010 8:51 pm

Re: C# API - tik4net on GitHub

Thu Apr 06, 2017 10:58 pm

Any chances that ther would come a VB.NET example on how to use the DLL.
I have worked with it for some time now without any luck.
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Thu Apr 06, 2017 11:26 pm

What about using some online converter?

This is result of http://converter.telerik.com/ converter for projects root page examples:

1) Add references:
* tik4net.dll
* tik4net.objects.dll

2) Try to modify this example:
Imports tik4net
Imports tik4net.Objects
Imports tik4net.Objects.Ip.Firewall

Namespace Test
	Public Class MyTest
		Public Sub TestMikrotik()	
			Using connection As ITikConnection = ConnectionFactory.CreateConnection(TikConnectionType.Api)
				connection.Open(HOST, USER, PASS)

				Dim cmd As ITikCommand = connection.CreateCommand("/system/identity/print")
				Dim identity = cmd.ExecuteScalar()
				Console.WriteLine("Identity: {0}", identity)

				Dim logs = connection.LoadList(Of Log)()
				For Each log As Log In logs
					Console.WriteLine("{0}[{1}]: {2}", log.Time, log.Topics, log.Message)
				Next

				Dim fwf = New FirewallFilter() With { _
					.Chain = FirewallFilter.ChainType.Forward, _
					.Action = FirewallFilter.ActionType.Accept _
				}
				connection.Save(fwf)
			End Using
		End Sub
	End Class
End Namespace
UPDATE: fixed as recommended bellow.

D
Last edited by danikf on Sun Apr 09, 2017 10:11 pm, edited 3 times in total.
 
Centauri
Frequent Visitor
Frequent Visitor
Posts: 50
Joined: Sun Jun 06, 2010 8:51 pm

Re: C# API - tik4net on GitHub

Sun Apr 09, 2017 11:52 am

have newer have much luck with such converts.
It also gives some errors withe the lines

Dim logs = connection.LoadList(Of Log)()
Error BC30456 'LoadList' is not a member of 'ITikConnection'.

Dim firewallFilter = New FirewallFilter() With {
Error BC30002 Type 'FirewallFilter' is not defined.

connection.Save(firewallFilter)
Error BC30456 'Save' is not a member of 'ITikConnection'.

I just need to make a simple program to read all users for userman and be able to create new users.
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sun Apr 09, 2017 3:49 pm

Hi,

you must reference tik4net.objects.dll and import (use) namespace with tik4net extensions. I've updated previous example to full example class.

Hope it helps,
D
 
Centauri
Frequent Visitor
Frequent Visitor
Posts: 50
Joined: Sun Jun 06, 2010 8:51 pm

Re: C# API - tik4net on GitHub

Sun Apr 09, 2017 9:14 pm

It all most works
.
Key.Chain = firewallFilter.ChainType.Forward,
Error BC30451 'Key' is not declared. It may be inaccessible due to its protection level.
Error BC30980 Type of 'firewallFilter' cannot be inferred from an expression containing 'firewallFilter'.

Just in case you want to update yor code, can see you also have posted it on your Wiki

But all i need is to be able to get the user and profile list for
tool/user-manager/user/print
tool/user-manager/profile/print

I have managed to do it with the following code, don't know if its the best way to do it but it works the i just have to filter out the informations i need like id username and password.
Just in case others could make use if it.
Imports tik4net
Imports tik4net.Objects


Namespace Test
   Public Class MyTest
      Public Sub TestMikrotik()   
         Using connection As ITikConnection = ConnectionFactory.CreateConnection(TikConnectionType.Api)
            connection.Open(HOST, USER, PASS)

            Dim cmd As ITikCommand = connection.CreateCommandAndParameters("/tool/user-manager/user/print")
            Dim results = cmd.ExecuteList()

            For Each users In results
                Console.WriteLine(users)
            Next users

         End Using
      End Sub
   End Class
End Namespace
 
clarksheng
just joined
Posts: 5
Joined: Sat Sep 29, 2012 12:07 am

Re: C# API - tik4net on GitHub

Tue Apr 11, 2017 10:05 am

HI got 2 problems with tik4net.
1. I generated new entity at "/ip/hotspot/profiles/print" by entitygenerator, but tik4net keeps telling me unknow command.
the following is the newly generated entity,
        
        /// <summary>
        /// /ip/hotspot/profile/print: 
        /// </summary>
        [TikEntity("/ip/hotspot/profile/print")]
        public class ServerProfile
        {
            /// <summary>
            /// .tag: 
            /// </summary>
            [TikProperty(".tag")]
            public long Tag { get; set; }

            /// <summary>
            /// .id: 
            /// </summary>
            [TikProperty(".id", IsReadOnly = true, IsMandatory = true)]
            public string Id { get; private set; }

            /// <summary>
            /// name: 
            /// </summary>
            [TikProperty("name", IsMandatory = true)]
            public string Name { get; set; }

            /// <summary>
            /// hotspot-address: 
            /// </summary>
            [TikProperty("hotspot-address")]
            public string HotspotAddress { get; set; }

            /// <summary>
            /// html-directory: 
            /// </summary>
            [TikProperty("html-directory")]
            public string HtmlDirectory { get; set; }

            /// <summary>
            /// http-proxy: 
            /// </summary>
            [TikProperty("http-proxy")]
            public string HttpProxy { get; set; }

            /// <summary>
            /// smtp-server: 
            /// </summary>
            [TikProperty("smtp-server")]
            public string SmtpServer { get; set; }

            /// <summary>
            /// login-by: 
            /// </summary>
            [TikProperty("login-by")]
            public string LoginBy { get; set; }

            /// <summary>
            /// split-user-domain: 
            /// </summary>
            [TikProperty("split-user-domain")]
            public bool SplitUserDomain { get; set; }

            /// <summary>
            /// use-radius: 
            /// </summary>
            [TikProperty("use-radius")]
            public bool UseRadius { get; set; }

            /// <summary>
            /// default: 
            /// </summary>
            [TikProperty("default")]
            public bool Default { get; set; }

        }
2. With the above new entity doesn't work, I try to use the command to edit hotspot server profile by the following code:
            ITikCommand cmd = connection.CreateCommand("/ip/hotspot/profile/edit");
            cmd.AddParameter(TikSpecialProperties.Id, "0");
            cmd.AddParameter("name", "helloworld");
            cmd.ExecuteNonQuery();
however, tik4net keeps telling me unknow parameters.
Please help with either one, personally thinking the second problem is related to ".id" or "number" which I don't know what I should use as correct parameter. Thanks.
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Tue Apr 11, 2017 10:25 pm

Hi,

ad 1:
Please remove "/print" sufix -> [TikEntity("/ip/hotspot/profile")]
See https://github.com/danikf/tik4net/wiki/ ... m-entities for details.

ad 2:
You have to use .id property in format "*A"
See https://github.com/danikf/tik4net/wiki/ ... e-entities for details.

You have to know .id of the row to edit. You can read it via some kind of load (with/without filter).
See https://github.com/danikf/tik4net/wiki/ ... d-entities
Or nescafe2002's aswer (above this post): viewtopic.php?f=9&t=99954&start=50#p570685

Note: for some entities it is possible to use "name" in position of ".id", but not in this case. Numbers are not supported by API at all. For example of this usage see Eth1 test in tik4net.test project:
https://github.com/danikf/tik4net/blob/ ... aceTest.cs

Enjoy,
D
 
Centauri
Frequent Visitor
Frequent Visitor
Posts: 50
Joined: Sun Jun 06, 2010 8:51 pm

Re: C# API - tik4net on GitHub

Sat Apr 15, 2017 12:48 am

Hi i have a problem with the API and creating parameters.

When i do it manuel via the command line i use
tool user-manager user add customer= admin username="test007" password="nigher"
tool user-manager user create-and-activate-profile test007 profile=Always customer=admin

Via the API i can create the user with the following
Dim cmd As ITikCommand = connection.CreateCommandAndParameters("/tool/user-manager/user/add", "customer", "admin", "username", "test007", "password", "12345678")
cmd.ExecuteNonQuery()
But i have a problem setting the Profile since the API expect a parameter name but the command have no name like username when i create the user the first thing i have to enter her in the actual username and the API dosent support a blank parameter name like this.
Dim cmd As ITikCommand = connection.CreateCommandAndParameters("/tool/user-manager/user/create-and-activate-profile", "", "test007", "profile", "Always", "customer", "admin")
cmd.ExecuteNonQuery()
Any idea how i cn solve that ?
 
neoprogger
just joined
Posts: 13
Joined: Tue May 10, 2016 7:55 pm

Re: C# API - tik4net on GitHub

Thu Apr 20, 2017 4:36 pm

Hi,
Thanks for your Project.
Whenever I try to add a mac-based-vlan rule I can see the new rule, but every value is populated with 0.

Dim cmd As ITikCommand = connection.CreateCommandAndParameters("/interface/ethernet/switch/mac-based-vlan/add", "src-mac-address=112233445566", "new-customer-vid=15")
same with
Dim cmd As ITikCommand = connection.CreateCommandAndParameters("/interface/ethernet/switch/mac-based-vlan/add", "src-mac-address=11:22:33:44:55:66", "new-customer-vid=14")
and with
Dim cmd As ITikCommand = connection.CreateCommandAndParameters("/interface/ethernet/switch/mac-based-vlan/add","src-mac-address=11:22:33:44:55:66" "new-customer-vid", "15")

What is my fault?

Thanks

Alex
 
Centauri
Frequent Visitor
Frequent Visitor
Posts: 50
Joined: Sun Jun 06, 2010 8:51 pm

Re: C# API - tik4net on GitHub

Sat Apr 22, 2017 3:53 pm

Try this
Dim cmd As ITikCommand = connection.CreateCommandAndParameters("/interface/ethernet/switch/mac-based-vlan/add", "src-mac-address","11:22:33:44:55:66", "new-customer-vid","14")
 
User avatar
irghost
Member Candidate
Member Candidate
Posts: 273
Joined: Sun Feb 21, 2016 1:49 pm
Contact:

Re: C# API - tik4net on GitHub

Tue Jun 27, 2017 9:48 am

Hi all
I'm looking for something that's helps me with "/PPP active"
with High Level
MTCNA MTCRE MTCTCE MTCUME MTCWE MTCIPv6E MTCINE
میکروتیک فا برای فارسی زبان ها
Mikrotik Certified Consultant
https://mikrotikfa.com
 
nescafe2002
Member
Member
Posts: 489
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: C# API - tik4net on GitHub

Tue Jun 27, 2017 10:47 am

Please follow instructions on https://github.com/danikf/tik4net/wiki/ ... I-entities

Example:
void Main()
{
  using (var conn = tik4net.ConnectionFactory.OpenConnection(TikConnectionType.Api, "192.168.88.1", 8728, "admin", "mypassword"))
  {
    var list = conn.LoadAll<PppActive>();
  }
}

[TikEntity("/ppp/active", IncludeDetails = true)]
public class PppActive
{
  [TikProperty(".id")]
  public string Id { get; private set; }

  [TikProperty("name")]
  public string Name { get; private set; }

  [TikProperty("service")]
  public string Service { get; private set; }

  [TikProperty("caller-id")]
  public string CallerId { get; private set; }

  [TikProperty("address")]
  public string Address { get; private set; }

  [TikProperty("uptime")]
  public string Uptime { get; private set; }

  [TikProperty("encoding")]
  public string Encoding { get; private set; }

  [TikProperty("session-id")]
  public string SessionId { get; private set; }

  [TikProperty("limit-bytes-in")]
  public int LimitBytesIn { get; private set; }

  [TikProperty("limit-bytes-out")]
  public int LimitBytesOut { get; private set; }

  [TikProperty("radius")]
  public bool Radius { get; private set; }
}
 
Turkialawlqy
just joined
Posts: 1
Joined: Thu Jul 13, 2017 8:54 am

Re: C# API - tik4net on GitHub

Thu Jul 13, 2017 9:04 am

Hi
How to use this command in tik4net
/tool user-manager user print where !actual-profile
 
khalil
just joined
Posts: 1
Joined: Sun Aug 06, 2017 12:36 am

Hi Please how to delete the user HotSpot using tik4net vb.net

Sun Aug 06, 2017 12:45 am

Hi
Please how to delete the user HotSpot using tik4net vb.net
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sat Dec 30, 2017 5:23 pm

I have just published version 3.0.0

Whats new:
* BETA: Support for NetCoreApp and NetStandard (functional with Xamarin on Android devices etc.)
* Some bug fixies and updates

Enjoy,
D
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Tue Jan 02, 2018 6:46 pm

Just published 3.0.1 version on nuget (*.zip is too large for this site).

Whats new:
*.xml documentation for visual studio.
 
MarkLFT
just joined
Posts: 14
Joined: Mon Apr 23, 2012 7:22 am

Re: C# API - tik4net on GitHub

Mon Mar 05, 2018 12:44 pm

I have found this library to very helpful, we use the hotspot features a lot. But we are now looking to expand to use User Manager, do you have any plans to allow users and profiles etc. to be created using objects the same at the Hotspot users.

I have been tasked with setting up a MUM server for different departments to use, so each dept will have their own set of users and profiles. Although I am not 100% certain that is possible.

Many thanks and keep up the good work.
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sun Apr 01, 2018 11:36 am

Hi Mark,
tik4net is just API - it allows you to perform all operations you are able to do with mikrotik API (and almost 100% operations you could achieve with mikrotik console). If you are missing some highlevel objects, you could ask someone/me for creating them or you could create classes by yourself. See wiki links how to do it:
https://github.com/danikf/tik4net/wiki/ ... I-entities
https://github.com/danikf/tik4net/wiki/ ... m-entities

I am not super expert in mikrotik, so your question should be answered by someone else :-)

Enjoy,
D
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sun Apr 01, 2018 6:13 pm

Hi,
version 3.1.0.0 published.

Whats new:
* XML documentation embeded also in *.zip
* Connection open timeout support
* WOL support
* small improovements

Enjoy,
D
 
User avatar
az1984
newbie
Posts: 28
Joined: Thu Sep 14, 2017 3:58 pm
Location: Germany

Re: C# API - tik4net on GitHub

Thu Apr 26, 2018 10:16 am

First of all: Great work!

I just started to play around with tik4net and C#, but I got a little trouble.

If I use your examples and create a WindowsConsoleApplication everything works as it should. Problems are starting when I try to do the same within a WindowsFormApplication. I use exactly the same code and paste it within action for a button on a form:
private void button1_Click(object sender, EventArgs e)
        {
            using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
            {
                connection.Open("192.168.77.xxx", "admin", "pass");

                ITikCommand certcmd = connection.CreateCommand("/certificate/add",
                    connection.CreateParameter("name", "test"),
                    connection.CreateParameter("common-name", "test.com"),
                    connection.CreateParameter("key-size", "2048"),
                    connection.CreateParameter("key-usage", "crl-sign,key-cert-sign"),
                    connection.CreateParameter("days-valid", "365"));
                
                certcmd.ExecuteAsync(response =>
                {
                    Console.WriteLine(response.GetResponseField(""));
                });
                Console.WriteLine("Certificate created - press ENTER");
                Console.ReadLine();
            }
        }
If I run my application now, I got an "Exception not handled error" saying no connection possible.

Guess I need some help here.
 
hardwarematik
just joined
Posts: 3
Joined: Thu May 03, 2018 12:26 am

Re: C# API - tik4net on GitHub

Tue May 08, 2018 12:39 am

First of all: Great work!

I just started to play around with tik4net and C#, but I got a little trouble.

If I use your examples and create a WindowsConsoleApplication everything works as it should. Problems are starting when I try to do the same within a WindowsFormApplication. I use exactly the same code and paste it within action for a button on a form:
private void button1_Click(object sender, EventArgs e)
        {
            using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
            {
                connection.Open("192.168.77.xxx", "admin", "pass");

                ITikCommand certcmd = connection.CreateCommand("/certificate/add",
                    connection.CreateParameter("name", "test"),
                    connection.CreateParameter("common-name", "test.com"),
                    connection.CreateParameter("key-size", "2048"),
                    connection.CreateParameter("key-usage", "crl-sign,key-cert-sign"),
                    connection.CreateParameter("days-valid", "365"));
                
                certcmd.ExecuteAsync(response =>
                {
                    Console.WriteLine(response.GetResponseField(""));
                });
                Console.WriteLine("Certificate created - press ENTER");
                Console.ReadLine();
            }
        }
If I run my application now, I got an "Exception not handled error" saying no connection possible.

Guess I need some help here.
Hi I had same problem than and I solve deleteing the tik4net 3.10 unit on Visual Studio (Nuget) and installing 3.0.1 and works fine, for some errors maybe 3.10 the last at this moment have this error of timeout still no solve at least for me on Mikrotik 5.20, using Api port NOT ApiSSL port. I hope to help you
 
User avatar
saputra19
just joined
Posts: 7
Joined: Fri Mar 23, 2018 3:11 pm
Location: indonesia
Contact:

Re: C# API - tik4net on GitHub

Mon May 21, 2018 4:54 pm

Hi Danikf
how to perform command below?
/ip hotspot user profile delete [find name=BLABLABLA]

its work perfectly in terminal, but when i am use it in vb.net, it says " no such command"
I really appreciate your instructions
 
User avatar
saputra19
just joined
Posts: 7
Joined: Fri Mar 23, 2018 3:11 pm
Location: indonesia
Contact:

Re: C# API - tik4net on GitHub

Wed May 23, 2018 4:48 pm

Hi Danikf
how to perform command below?
/ip hotspot user profile delete [find name=BLABLABLA]

its work perfectly in terminal, but when i am use it in vb.net, it says " no such command"
I really appreciate your instructions
hi
i have found solution about my question, this is my code on vb.net and its work perfectly
Using connection As ITikConnection = ConnectionFactory.CreateConnection(TikConnectionType.Api)
            connection.Open(Form2.HostTB.Text, Form2.LoginTB.Text, Form2.PassTB.Text)
            Dim cmd As ITikCommand = connection.CreateCommandAndParameters("/ip/hotspot/user/profile/remove")
            cmd.AddParameter(TikSpecialProperties.Id, CBdelprof.Text)
            cmd.ExecuteNonQuery()
            MessageBox.Show("Profile Deleted")
now, i have problem with counting expired users. this code work in terminal
/ip hotspot user print count-only where comment=expired.user
how to perform this command in tik4net?
thanks
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sat Jun 30, 2018 3:01 pm

It is API related question :-)

The naive way (without using count-only) could be something like:
connection.LoadAll<UserProfile>().Where(u=>u.Comment="expired.user").Count();
D
Last edited by danikf on Sat Jul 07, 2018 2:34 pm, edited 2 times in total.
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Fri Jul 06, 2018 12:32 am

Hi,

new version 3.2.0.0 was released.

Whats new:
* Connection.Open fixed (mentioned by az1984, hardwarematik)
* New 6.43 login process supported (credits:DaveSchmid)

D
 
ww1977
just joined
Posts: 1
Joined: Wed Jul 25, 2018 8:02 am

Re: C# API - tik4net on GitHub

Wed Jul 25, 2018 8:11 am

Hi
On the device, the API port is changed from the standard 8728 to the other. How do I specify the port when connecting?
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Wed Jul 25, 2018 9:18 pm

Use ConnectionFactory.OpenConnection/connection.Open method overload with port.
connection.Open(HOST, PORT, USER, PASS);
D
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Fri Aug 10, 2018 6:24 pm

Question (posted as Github issue):
To obtain the Rx and Tx values ​​of the interface, in which way it is done, thank you in advance.
Answer:
var ethIface = Connection.LoadSingle<Interface>(Connection.CreateParameter("name", "ether1"));
var rx = ethIface.RxByte;
D
 
hreynaldoh
just joined
Posts: 1
Joined: Wed Aug 08, 2018 3:40 am

Re: C# API - tik4net on GitHub

Sun Aug 12, 2018 3:40 am

Question (posted as Github issue):
To obtain the Rx and Tx values ​​of the interface, in which way it is done, thank you in advance.
Answer:
var ethIface = Connection.LoadSingle<Interface>(Connection.CreateParameter("name", "ether1"));
var rx = ethIface.RxByte;
D
Rx o Tx in real time of each interfcace not RxByte of interface?
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sun Aug 12, 2018 2:14 pm

Hi,
you can wait for next release or use this code (taken from its code base).

D
        /// <summary>
        /// Gets snapshot of actual traffic RX/TX values for given <paramref name="interfaceName"/>.
        /// </summary>
        public static InterfaceMonitorTraffic GetInterfaceMonitorTrafficSnapshot(ITikConnection connection, string interfaceName)
        {
            var cmd = connection.CreateCommand("/interface/monitor-traffic",
                connection.CreateParameter("interface", interfaceName, TikCommandParameterFormat.NameValue),
                connection.CreateParameter("once", "", TikCommandParameterFormat.NameValue));
            var result = cmd.LoadList<InterfaceMonitorTraffic>().Single();

            return result;
        }
     
And the InterfaceMonitorTraffic class:

    /// <summary>
    /// /interface/monitor-traffic
    /// NOTE: use <see cref="InterfaceMonitorTraffic.GetSnapshot"/> or with some kind of bulk/async load
    /// </summary>
    [TikEntity("/interface", IncludeDetails = true, IsReadOnly = true)]
    public class InterfaceMonitorTraffic
    {
        /// <summary>
        /// name
        /// </summary>
        [TikProperty("name", IsMandatory = true, IsReadOnly = true)]
        public string Name { get; private set; }

        /// <summary>
        /// rx-packets-per-second
        /// </summary>
        [TikProperty("rx-packets-per-second", IsMandatory = true, IsReadOnly = true)]
        public string RxPacketsPerSecond { get; private set; }

        /// <summary>
        /// rx-bits-per-second
        /// </summary>
        [TikProperty("rx-bits-per-second", IsMandatory = true, IsReadOnly = true)]
        public string RxBitsPerSecond { get; private set; }

        /// <summary>
        /// rx-drops-per-second
        /// </summary>
        [TikProperty("rx-drops-per-second", IsMandatory = true, IsReadOnly = true)]
        public string RxSropsPerSecond { get; private set; }

        /// <summary>
        /// rx-errors-per-second
        /// </summary>
        [TikProperty("rx-errors-per-second", IsMandatory = true, IsReadOnly = true)]
        public string RxErrorsPerSecond { get; private set; }        

        /// <summary>
        /// tx-packets-per-second
        /// </summary>
        [TikProperty("tx-packets-per-second", IsMandatory = true, IsReadOnly = true)]
        public string TxPacketsPerSecond { get; private set; }

        /// <summary>
        /// tx-bits-per-second
        /// </summary>
        [TikProperty("tx-bits-per-second", IsMandatory = true, IsReadOnly = true)]
        public string TxBitsPerSecond { get; private set; }

        /// <summary>
        /// tx-drops-per-second
        /// </summary>
        [TikProperty("tx-drops-per-second", IsMandatory = true, IsReadOnly = true)]
        public string TxSropsPerSecond { get; private set; }

        /// <summary>
        /// tx-errors-per-second
        /// </summary>
        [TikProperty("tx-errors-per-second", IsMandatory = true, IsReadOnly = true)]
        public string TxErrorsPerSecond { get; private set; }
    }
 
User avatar
saputra19
just joined
Posts: 7
Joined: Fri Mar 23, 2018 3:11 pm
Location: indonesia
Contact:

Re: C# API - tik4net on GitHub

Fri Aug 31, 2018 2:56 pm

hi daniel,
can you add loadlist of ppp
-ppp active
-ppp profile
-ppp secret

like hotspot command
connection.LoadList(Of HotspotUser)()
its very easy to use. Hope you can add for ppp

thank you very much

P.S i am using vb.net
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sat Sep 01, 2018 11:17 pm

 
User avatar
saputra19
just joined
Posts: 7
Joined: Fri Mar 23, 2018 3:11 pm
Location: indonesia
Contact:

Re: C# API - tik4net on GitHub

Mon Sep 03, 2018 10:26 am

:D :D :D :D thank you !!!!
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Mon Sep 03, 2018 7:40 pm

Hi,

new version 3.3.0 released. Upgrade is recommended!

Whats new:
  • Support for own tag sent to sync commands in commandText
  • Native support for entities loaded in different way than /print
  • Connection.LoadByName extension
  • Connection extension methods for entity static methods
  • Connection .ExecuteNonQuery, .ExecuteScalar extensions
  • ApiCommand onDoneCallback for LoadAsync
  • Connection.SendTagWithSyncCommand option
New classes:
  • InterfaceMonitorTraffic
  • WirelessChannels, WirelessSniffer ( (c) AsafMag)
  • PPP objects
Fixed:
  • Exception from conncetion.Close
  • Typo in InterfaceWireless
  • Correct behavior when connection was forced to close
  • Parallel async commands cancel fix
Enjoy,
D
 
User avatar
saputra19
just joined
Posts: 7
Joined: Fri Mar 23, 2018 3:11 pm
Location: indonesia
Contact:

Re: C# API - tik4net on GitHub

Sat Sep 22, 2018 2:13 pm

Hi daniel
thanks for upgrade. its awesome!!
but i got some problem in InterfaceMonitorTraffic object. If i use this object to RB 750Gr3, it says "Missing Word with name rx-drops-per-second". but working excellent in RB951Ui-2nD.
and this SS of interface monitor on terminal were 750Gr3 not contains rx-drops-per-second
https://ibb.co/nyY9K9

what should i do?
thanks
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sun Sep 23, 2018 3:51 pm

Hi,
fixed in dev branch: https://github.com/danikf/tik4net/commi ... ffeea6cb00

You can fix issues like this manually by creating new copy of entity and making some fields optional (IsMandatory=false) or by deleting them. Than just use your type in the same place as original one.

BTW - I believe that it is more likely problem of routeros version than problem of different HW.

D
PS: see this tutorial for custom objects:
https://github.com/danikf/tik4net/wiki/ ... m-entities
https://github.com/danikf/tik4net/wiki/ ... -API-tools
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Wed Sep 26, 2018 9:56 pm

Version 3.4. released.

https://github.com/danikf/tik4net/releases/tag/v3.4

Whats new:
tool/traceroute entity + helpers
tool/ping helpers
Command.ExecuteWithDuration fix
InterfaceMonitorTraffic fix

D

Who is online

Users browsing this forum: No registered users and 9 guests