Community discussions

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

C# API - tik4net on GitHub

Fri Aug 28, 2015 12:54 am

I have just published my API client for .NET. It implements execution of parallel queries which are easily handled due to ADO.NET-like interface + O/R mapper like extensions to provide strong-typed experience (it supports both single entity and list of entities).

Please leave message in this thread if you need some feature to be implemented or if you have any relevant question.

Repository: https://github.com/danikf/tik4net
Wiki: https://github.com/danikf/tik4net/wiki
How to use: https://github.com/danikf/tik4net/wiki/ ... et-library
nuget package: https://www.nuget.org/packages/tik4net/
Releases (usage of nuget package is recommended):
tik4net-3.4.0.zip
tik4net-3.3.0.zip
Features:
  • ITikConnection lowlevel API (send command / read response, async commands)
  • ADO.NET like api (ITikCommand + various Execute... methods)
  • O/R mapper to/from entity classes. (connection.LoadList<Log>())
  • Release also contains C# entity code generators to support semi-automatic generation of custom entities from running mikrotik router and from mikrotik wiki site (from oficial documentation)
  • API-SSL support
  • New mikrotik (from v. 6.43) login process support
  • Dlls builded for .NET 3.5, 4.0, 4.5.x, 4.6.x, netcoreapp1.1, netcoreapp2.0, netstandart1.3, netstandard1.4, netstandard1.6
  • Functional with xamarin and other .NET runtimes based on Mono
Reference downloaded dlls only if you are not able to use nuget package or GitHub sources.
Examples
For read/write examples see API comparison CRUD examples wiki page.

Read and print mikrotik router identity
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
  connection.Open(HOST, USER, PASS);
  ITikCommand cmd = connection.CreateCommand("/system/identity/print");
  Console.WriteLine(cmd.ExecuteScalar());
}
Example of async Torch command
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
  connection.Open(HOST, USER, PASS);
  var loadingContext = connection.LoadAsync<ToolTorch>(
    torchItem => Console.WriteLine(torchItem.ToString()),
    error => Console.WriteLine(error.ToString()),                                                
    connection.CreateParameter("interface", interfaceName),   
    connection.CreateParameter("port", "any"),
    connection.CreateParameter("src-address", "0.0.0.0/0"),
    connection.CreateParameter("dst-address", "0.0.0.0/0"));

  Console.ReadLine();
  loadingContext.Cancel();
}
read all log entries
var logs = connection.LoadList<Log>();
foreach (Log log in logs)
{
    Console.WriteLine("{0}[{1}]: {2}", log.Time, log.Topics, log.Message);
}
firewall management
//find first firewall rule
var firstFirewallRule = connection.LoadAll<FirewallFilter>().First();

// create new firewall rule as first rule in list
var firewallFilter = new FirewallFilter()
{
   Chain = FirewallFilter.ChainType.Forward,
   Action = FirewallFilter.ActionType.Accept,
};
connection.Save(firewallFilter);
connection.Move(firewallFilter, firstFirewallRule);
NOTE: please do not use deprecated 0.9.7 incompatible version of tik4net from https://code.google.com/p/mikrotik4net/.
You do not have the required permissions to view the files attached to this post.
Last edited by danikf on Wed Sep 26, 2018 9:54 pm, edited 29 times in total.
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Fri Aug 28, 2015 1:04 am

Chupaka - thank you for inspiration how to handle paralel queries.

D
BTW: both your and mine code are not realy thread-safe ;-)
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Wed Sep 16, 2015 8:31 pm

Released new version with updates. Added versions for .NET 3.5, .NET 4.0 and .NET 4.5.2
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sun Sep 20, 2015 3:29 pm

Released new version 1.2.0.0 with enum support (as field values) and with C# entity code generators.

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

Re: C# API - tik4net on GitHub

Tue Sep 22, 2015 11:45 pm

Example of highlevel API usage (dev branch on GitHub):
// renew IP on dhcp-client interface
connection.LoadAll<IpDhcpClient>().First().Release(connection);
 
MarkLFT
just joined
Posts: 14
Joined: Mon Apr 23, 2012 7:22 am

Re: C# API - tik4net on GitHub

Wed Sep 30, 2015 10:49 am

This looks like a great project, and one that would be very useful. Thanks for sharing it with us.

I have just downloaded it and spent some time going through the samples and classes, but I did not notice anything to do with Hotspot, in particular creating and deleting user accounts. Is this functionality available in the library? If not, is it something you will be adding anytime soon?

Again, many thanks.

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

Re: C# API - tik4net on GitHub

Wed Sep 30, 2015 10:20 pm

Hello,

I am going to import hotspot objects very soon (one week?), but I need betatesters, becase I am not using this feature. If you wold participate in betatesting, your help will be appreciated.

Or you can create your own classes (see TikEntity and TikProperty attributes) and use it with O/R mapper like extensions.

Or you can use ADO like api - handle hotspot management via standard "Execute" command interface like other libraries :-)

D
Last edited by danikf on Thu Oct 01, 2015 12:24 am, edited 1 time in total.
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Thu Oct 01, 2015 12:15 am

Released new version 1.2.2.0 with hotspot user entities (beta).
using tik4net.Objects;
using tik4net.Objects.Ip.Hotspot;
var user = new HotspotUser()
{
    Name = "TEST",
    LimitUptime = "1:00:00",
    Password = "secretpass"
};
_connection.Save(user);
Enjoy,
D
 
MarkLFT
just joined
Posts: 14
Joined: Mon Apr 23, 2012 7:22 am

Re: C# API - tik4net on GitHub

Thu Oct 01, 2015 8:43 am

We have a test facility in our office here, and use the Hotspot functionality quite extensively, so would be happy to help test it for you.
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Fri Oct 16, 2015 11:32 pm

Published version 1.3.0.0.

New highlevel entities:
* Hotspot users
* Interface (eth/wlan)
var list = Connection.LoadAll<InterfaceWireless.WirelessRegistrationTable>();
Enjoy,
D
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Wed Oct 28, 2015 12:54 am

Version 1.4.0.0 released:

* Fixed word length calculation (credits: h44z)
* Hotspot user management fixed
* Async API refactoring (cleaning)

Enjoy,
D
 
normangon
just joined
Posts: 18
Joined: Thu Oct 16, 2008 8:06 pm
Location: Venezuela
Contact:

Re: C# API - tik4net on GitHub

Fri Dec 18, 2015 10:49 am

Impressive work :D I made use of the older deprecated version but this is awesome hands down! Now Testing!
 
geraneto
just joined
Posts: 3
Joined: Sat Dec 19, 2015 2:27 am

Re: C# API - tik4net on GitHub

Sat Dec 19, 2015 2:32 am

good evening...
Must capture all connections from an IP address /ip/firewall/connections/print where src-address ~192.168.2.2 . How could perform it? thank you
 
geraneto
just joined
Posts: 3
Joined: Sat Dec 19, 2015 2:27 am

Re: C# API - tik4net on GitHub

Mon Dec 21, 2015 1:21 am

good evening...
I can not run /IP/firewall/connection/print where src-address ~ "192.168.2.2".
I need to capture the dst -address.

Obrigado .
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Mon Dec 21, 2015 8:50 pm

Hi,

there are many ways how to handle this task:
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
  connection.Open(HOST, USER, PASS);
1) Via direct API call (low-level access):
  string[] command = new string[]
  {
    "/ip/firewall/connection/print",
    "?src-address=192.168.3.103"
  };
  var result = connection.CallCommandSync(command);
2) Via ADO.NET like API:
  var command = connection.CreateCommandAndParameters("/ip/firewall/connection/print",
    "src-address", "192.168.3.103");
  var result = command.ExecuteList();
3) Via highlevel O/R mapper like API:
  // This class will be part of the next release, but you can just put it in your code
    [TikEntity("ip/firewall/connection")]
    public class FirewallConnection
    {
        [TikProperty(".id", IsReadOnly = true, IsMandatory = true)]
        public string Id { get; private set; }

        [TikProperty("connection-mark", IsReadOnly = true)]
        public string ConnectionMark { get; private set; }

        [TikProperty("connection-type", IsReadOnly = true)]
        public string ConnectionType { get; private set; }

        [TikProperty("dst-address", IsReadOnly = true)]
        public string DstAddress { get; private set; }

        [TikProperty("protocol", IsReadOnly = true)]
        public string Protocol { get; private set; }

        [TikProperty("src-address", IsReadOnly = true)]
        public string SrcAddress { get; private set; }

        [TikProperty("tcp-state", IsReadOnly = true)]
        public string TcpState { get; private set; }

        [TikProperty("timeout", IsReadOnly = true)]
        public string Timeout { get; private set; }
    }

  // And the code:
  using tik4net.Objects;
  ...
  var result = connection. LoadList<FirewallConnection>(
    connection.CreateParameter("src-address", "192.168.3.103"));
4) You can skip filtering part, select all connection items and filter them via C# code (LINQ?). Slow, but simple...

Enjoy,
D
 
geraneto
just joined
Posts: 3
Joined: Sat Dec 19, 2015 2:27 am

Re: C# API - tik4net on GitHub

Tue Dec 22, 2015 12:53 pm

good Morning...
I performed a test as follows

using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
connection.Open(HOST, USER, PASS);
var command = connection.CreateCommandAndParameters("/ip/firewall/connection/print","src-address","192.168.3.69");
var result = command.ExecuteList();

foreach (var c in result)
{
listBox1.Items.Add(c);
}
}

however I have no result
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Tue Dec 22, 2015 6:55 pm

Probably there is no active connection from ip 192.168.3.69 to router (or connection tracking is switched off in mikrotik configuration).

Try to load all connections without filter:
var command = connection.CreateCommandAndParameters("/ip/firewall/connection/print"); 
var result = command.ExecuteList();
Enjoy,
D
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Fri Jan 01, 2016 8:21 pm

Released new version 1.5.0.0.

Whats new:
* TikListMerge ferature - see https://github.com/danikf/tik4net/wiki/TikListMerge
* FirewallConnection.ConnectionTracking entity
* Bug fixies

Enjoy,
D
 
tmak
just joined
Posts: 7
Joined: Mon Jan 25, 2010 3:07 pm

Re: C# API - tik4net on GitHub

Wed Jan 27, 2016 1:06 pm

Hi danikf
Good work man, Thanks for sharing it.
I am using your dll in vb.net project, can you explain how to set ?#operations by CreateCommandAndParameters to applies operations to the values in the stack.
Example to execute this query.
/interface/print
?type=ether
?type=vlan
?#|
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Thu Jan 28, 2016 10:27 am

Hi,
I have just updated github sources (update will be part of the next release). With updated version you can simply format command text with filter.

Untyped version:
            var cmd = Connection.CreateCommandAndParameters(@"/interface/print
                            ?type=ether
                            ?type=wlan
                            ?#|");
            var list = cmd.ExecuteList();
Strong-typed version
            var cmd = Connection.CreateCommandAndParameters(@"/interface/print
                            ?type=ether
                            ?type=wlan
                            ?#|");
            var list = cmd.LoadList<Interface>();
The main reasson why parameters stack is not supported is that it will bring high complexity into API (expression trees?). So, I will decide (for this time) not to support this construction via parameters (may be in the future).

Enjoy,
D
 
tmak
just joined
Posts: 7
Joined: Mon Jan 25, 2010 3:07 pm

Re: C# API - tik4net on GitHub

Fri Jan 29, 2016 1:17 am

Thanks, for the fast update.
 
tmak
just joined
Posts: 7
Joined: Mon Jan 25, 2010 3:07 pm

Re: C# API - tik4net on GitHub

Sun Jan 31, 2016 11:48 am

Hi,
Can you add Bridge Filter object in next update to manipulate Bridge Filter Rules just like we can do on high level of Firewall Filters with your code.
Thanks
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Tue Feb 02, 2016 12:04 am

I have committed Alpha version of Bridge entities to GitHub. I'll appreciate your feed-back.
            var filter = new InterfaceBridge.BridgeFilter()
            {
                Chain = InterfaceBridge.BridgeFilter.ChainType.Forward,
                Action = InterfaceBridge.BridgeFilter.ActionType.Accept,
            };
            Connection.Save(filter);
You can still create your own classes and use them with my extension methods (see post abbove). Just use the right attributes ...

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

Re: C# API - tik4net on GitHub

Tue Feb 02, 2016 8:10 pm

Published new version 1.6.0.0

Whats new:
* Added support for formated commands
* Added Bridge entities (InterfaceBridge, BridgeNat, BridgeFilter)
            var nat = new InterfaceBridge.BridgeNat()
            {
                Chain = InterfaceBridge.BridgeFirewallBase.ChainType.Forward,
                Action = InterfaceBridge.BridgeNat.ActionType.Accept,
            };
            Connection.Save(nat);
Enjoy,
D
 
tmak
just joined
Posts: 7
Joined: Mon Jan 25, 2010 3:07 pm

Re: C# API - tik4net on GitHub

Wed Feb 03, 2016 1:18 pm

Hi Daniel Frantik,

I am using your dll in VB.net project to edit bridge filters in ROS by API. New update is also working fine,

It make easy my work. Please add some more examples in VB about new future you add in your project. It will make working easy for new persons.

Thanks.
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Fri Feb 05, 2016 11:11 pm

api-ssl support added (github sources).
https://github.com/danikf/tik4net/wiki/SSL-connection
    using (var conection = ConnectionFactory.OpenConnection(TikConnectionType.ApiSsl, host, user, pass))
    {
      // do something usefull
    }
Looking for betatesters !!!

Enjoy,
D
 
meizoel
just joined
Posts: 7
Joined: Thu Feb 18, 2016 7:31 am

Re: C# API - tik4net on GitHub

Thu Feb 18, 2016 7:36 am

Hai dani :D

i have test your tik4net and i have add and modified some object on tik4net object..

btw i have success implement n reference it on my visual studio project 2012 for desktop and web c#...
the software created by me using tik4net dll has running from 1 februari 2015...

but i have some question can you sent me your email and if you give me some permission to upload tik4net modify i will upload it to tik4net github but of course i need your permisiion :D...
api-ssl support added (github sources).
https://github.com/danikf/tik4net/wiki/SSL-connection
    using (var conection = ConnectionFactory.OpenConnection(TikConnectionType.ApiSsl, host, user, pass))
    {
      // do something usefull
    }
Looking for betatesters !!!

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

Re: C# API - tik4net on GitHub

Thu Feb 18, 2016 12:26 pm

Hi,

your help would be welcome.

1) Fork projekt on github
2) Do some changes & commit them
3) Send pull request

See https://guides.github.com/activities/co ... en-source/

D
 
meizoel
just joined
Posts: 7
Joined: Thu Feb 18, 2016 7:31 am

Re: C# API - tik4net on GitHub

Thu Feb 18, 2016 2:30 pm

Hi,

your help would be welcome.

1) Fork projekt on github
2) Do some changes & commit them
3) Send pull request

See https://guides.github.com/activities/co ... en-source/

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

Re: C# API - tik4net on GitHub

Thu Feb 18, 2016 3:27 pm

Released new version 1.8.0.0.

Whats new:
* API-SSL support (alpha)
* Additional hotspot classes (credits: D-Bullock)
* Mikrotik time helper class (credits: D-Bullock)
* nuget support

Enjoy,
D
 
meizoel
just joined
Posts: 7
Joined: Thu Feb 18, 2016 7:31 am

Re: C# API - tik4net on GitHub

Wed Feb 24, 2016 10:23 am

Hai Dany...

i have some trouble installing .dll file of tik4net...

when i running the application with referrence of tik4net.dll on pc with visual studio 2012 there are no error code...
but when i running it on pc without visual studio 2012 there are show error related for tik4net.dll the error message say there are missing dependecy "api-ms-win-core.dll" file for tik4net...

can you help me :D

best regards
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Wed Feb 24, 2016 6:28 pm

Hi,

according to http://stackoverflow.com/questions/1702 ... l-problems - I am expecting that there is some dependency on VS redistributable package in your custom code - not in tik4net ...

tik4net, tik4net.objects references only: mscorlib.dll, system.dll, system.core.dll

I am 100% sure that I am using tik4net in project hosted on computer with WinXp without visual studio at all.

NOTE: do you have installed .NET redistributable on that computer?

D
 
diegotormes
Frequent Visitor
Frequent Visitor
Posts: 64
Joined: Wed Feb 15, 2006 11:45 pm

Re: C# API - tik4net on GitHub

Wed Feb 24, 2016 7:34 pm

Released new version 1.8.0.0.

Whats new:
* API-SSL support (alpha)
* Additional hotspot classes (credits: D-Bullock)
* Mikrotik time helper class (credits: D-Bullock)
* nuget support

Enjoy,
D

Congrats, you guys are doing a great job on this library!

Diego.
 
Spring
just joined
Posts: 16
Joined: Mon Aug 01, 2011 8:14 pm

Re: C# API - tik4net on GitHub

Fri Mar 04, 2016 11:17 am

Hello everyone..!

I'm currently using tik4net 1.8.0 with VB...
I tried to populate all interfaces into a listbox and it's done pretty simple with this:
Dim iface = con.CreateCommand("/interface/print")
Dim show = iface.ExecuteList()
        For Each eth In show
            lb1.Items.Add(eth)
        Next eth
and it returned:

ApiReSentence:.id=*1|name=ether1|type=ether|mtu=1500|dynamic=false|running=true|disabled=false
ApiReSentence:.id=*2|name=ether2|type=ether|mtu=1500|dynamic=false|running=true|disabled=false
ApiReSentence:.id=*3|name=ether3|type=ether|mtu=1500|dynamic=false|running=true|disabled=false


So, how do I view only specific properties, such as; only MTU value or only Type value as simple as in version 0.9.2 where I can use GetStringValueOrNull("xxxx", True) where "xxxx" is the item's name?

anyway, great work danikf.. thank you so much... :)
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Fri Mar 04, 2016 8:46 pm

Hi,

there are many possibilities how to manage it.

If you want to use this ADO like api, you should look at ITikReSentence interface (ExecuteList method returns IEnumerable<ITikReSentence>).

So your code will be (for example):
Dim iface = con.CreateCommand("/interface/print")
Dim show = iface.ExecuteList()
        For Each eth In show
            lb1.Items.Add(eth.GetResponseField("name"))
        Next eth
But I would recommend you to use higlevel API:
using tik4net.Objects;
using tik4net.Objects.Interface;

Dim show = con.LoadAll<Interface>()
        For Each eth In show
            lb1.Items.Add(eth.Name)
        Next eth
Enjoy,
D
 
Spring
just joined
Posts: 16
Joined: Mon Aug 01, 2011 8:14 pm

Re: C# API - tik4net on GitHub

Sat Mar 05, 2016 5:37 am

Both is tested and returned everything I need.. :D

I just need to edit this:
Dim show = con.LoadAll<Interface>()
into:
Dim show = con.LoadAll(Of [Interface])()
your examples saved my time from more deadly googling...
once again, thank you very much, danikf... you rock, man!! :) :)
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sat Mar 05, 2016 3:06 pm

 
Spring
just joined
Posts: 16
Joined: Mon Aug 01, 2011 8:14 pm

Re: C# API - tik4net on GitHub

Mon Mar 07, 2016 4:29 pm

Hi dani..
more question now.. :)

How do I code this winbox terminal using your libs:
/interface set ether2 name=LAN 
with highlevel API I found a clause "Where" but I never find a way how to use it... :(
and with ADO Like, I have no idea how to pick which interface to be changed using CreateCommand or CreateCommandAndParameters

more examples will be very helpful... ;)
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Tue Mar 08, 2016 1:17 am

Hi,

just load the entity which is representing the eth1 interface, update its property 'Name' and save it via connection.

Naive highevel api code:
var list = Connection.LoadAll<Interface>();
var eth = list.Where(iface => iface.DefaultName == "ether1").Single();
eth.Name = "newName";
Connection.Save(eth);
or use Execute scalar command in mikrotik API notation (see mikrotik wiki page for details: http://wiki.mikrotik.com/wiki/Manual:API)
var cmd = Connection.CreateCommand("/interface/set");
cmd.AddParameter(TikSpecialProperties.Id, "ether1");
cmd.AddParameter("name", "newName");
cmd.ExecuteNonQuery();
Which calls this command to mikrotik:
/interface/set
.id=ether1
name=newName
REMARKS: using names in place of .id is allowed only for some entities.
See http://wiki.mikrotik.com/wiki/API_command_notes.

Enjoy,
D
 
Spring
just joined
Posts: 16
Joined: Mon Aug 01, 2011 8:14 pm

Re: C# API - tik4net on GitHub

Tue Mar 15, 2016 6:38 am

Hi dani...
thx for the last response.. it works.. :)

I'm so sorry because I really not familiar to C# so the github docs was useless for me..

here's another question of mine...
this gave me what I need...
    Public Sub IPread()
        Dim ipList = con.LoadList(Of Ip.IpAddress)().ToArray
        dgvIP.DataSource = ipList

        Me.dgvIP.Columns(3).HeaderText = "Interface"
        Me.dgvIP.Columns(2).HeaderText = "Address"
        Me.dgvIP.Columns(1).Visible = False
        Me.dgvIP.Columns(0).Visible = False
        Me.dgvIP.Columns(4).Visible = False
        Me.dgvIP.Columns(5).Visible = False
        Me.dgvIP.Columns(6).Visible = False
        Me.dgvIP.Columns(7).Visible = False
        Me.dgvIP.Columns(8).Visible = False
        Me.dgvIP.Columns(9).Visible = False
        Me.dgvIP.Columns(10).Visible = False
    End Sub 
... but when I tried to do the same for dns and route, nothing appeared in the dgv or listbox...
Public Sub dnsRead()
Dim dnsList = con.LoadList(Of Ip.IpDns)().ToArray
dgvDNS.DataSource = dnsList
End Sub
or
Public Sub dnsRead()
        Dim dnsList = con.LoadList(Of Ip.IpDns)().ToArray
        For Each dns In dnsList
            lbDNS.Items.Add(dns.Servers)
        Next
End Sub
and for the ip/route... I didnt find it in object.ip so I tried to use con.createcommand(ip/route/print) but I don't know how to put the result into an array so they can be viewed in rows of dgv or listbox...

more help, please.. :)
 
meizoel
just joined
Posts: 7
Joined: Thu Feb 18, 2016 7:31 am

Re: C# API - tik4net on GitHub

Sun May 22, 2016 4:40 pm

Hai Danny,

i have succesfully integration tik4net to my desktop and web application

if you want to see you can cek on this https://youtu.be/UjYQQqzNrjk

btw i have one more question, i want to show interface ethernet to that website , but the rx and tx data must be update every 5 second,,

how to solve this case :D
 
jeroenp
Member Candidate
Member Candidate
Posts: 159
Joined: Mon Mar 17, 2014 11:30 am
Location: Amsterdam
Contact:

Re: C# API - tik4net on GitHub

Tue May 24, 2016 10:15 pm

480p makes it very hard to read. Can you re-render at a higher resolution?

--jeroen
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Fri May 27, 2016 4:46 pm

Hi,

nice work!

what about using javascript (JQuery?) and loading current RX/TX state per 5 seconds?

D
 
meizoel
just joined
Posts: 7
Joined: Thu Feb 18, 2016 7:31 am

Re: C# API - tik4net on GitHub

Sat May 28, 2016 8:26 am

Hi,

nice work!

what about using javascript (JQuery?) and loading current RX/TX state per 5 seconds?

D
can you show me the code if using from javascript, i have done with the sync command
 string[] command = new string[]
            {
                "/interface/monitor-traffic",
                "=interface=ether5-hotspot",
                "=once="
            };
                    var result = connection.CallCommandSync(command);
but i need it solve with async command , can you help me danniel :D
 
meizoel
just joined
Posts: 7
Joined: Thu Feb 18, 2016 7:31 am

Re: C# API - tik4net on GitHub

Sat May 28, 2016 8:27 am

480p makes it very hard to read. Can you re-render at a higher resolution?

--jeroen
oke next i will create on higher resolution, but it need time..
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sat May 28, 2016 12:03 pm

Hi,

easy soulution is to call your code per 5 sec (via JQuery) and show response in web UI.

Or you can use async code and store responses (somehow) in memor. When you do that, you can resturn more than one row to your JQuery request. But you have to be familiar with multithread code.
 List<ITikReSentence> responses = new List<ITikReSentence>();
 // ....
 var cmd = Connection.CreateCommandAndParameters("/interface/monitor-traffic", "interface", "ether1");
 cmd.ExecuteAsync(re => responses.Add(re));
 
 // ....
 cmd.CancelAndJoin(); //stops the interface monitoring
Enjoy,
D
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sat May 28, 2016 12:10 pm

Hi,

easy soulution is to call your code per 5 sec (via JQuery) and show response in web UI.

Or you can use async code and store responses (somehow) in memory (on you application server). When you do that, you can resturn more than one row to your JQuery request. But you have to be familiar with multithread code.
 List<ITikReSentence> responses = new List<ITikReSentence>();
 // ....
 var cmd = Connection.CreateCommandAndParameters("/interface/monitor-traffic", "interface", "ether1");
 cmd.ExecuteAsync(re => responses.Add(re));
 
 // ....
 cmd.CancelAndJoin(); //stops the interface monitoring
Enjoy,
D
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Sat May 28, 2016 4:11 pm

I have just published version 2.0.0.0.

Whats new:
* Encoding support
* Refactoring - nested classes removed (breaking change!)
* Bug fixies
* DNS objects added
* Ping object
const string HOST = "127.0.0.1";
const int MAX_CNT = 100;

List<ToolPing> responseList = new List<ToolPing>();
Exception responseException = null;

ITikCommand pingCommand = Connection.LoadAsync<ToolPing>(
  ping => responseList.Add(ping), //read callback
  exception => responseException = exception, //exception callback
  Connection.CreateParameter("address", HOST), Connection.CreateParameter("count", MAX_CNT.ToString()), Connection.CreateParameter("size", "64"));
// ...
Thread.Sleep(3 * 1000);
Connection.Close();
Enjoy,
D
 
meizoel
just joined
Posts: 7
Joined: Thu Feb 18, 2016 7:31 am

Re: C# API - tik4net on GitHub

Sun May 29, 2016 6:29 am

oke dani i will try this ..
Hi,

easy soulution is to call your code per 5 sec (via JQuery) and show response in web UI.

Or you can use async code and store responses (somehow) in memor. When you do that, you can resturn more than one row to your JQuery request. But you have to be familiar with multithread code.
 List<ITikReSentence> responses = new List<ITikReSentence>();
 // ....
 var cmd = Connection.CreateCommandAndParameters("/interface/monitor-traffic", "interface", "ether1");
 cmd.ExecuteAsync(re => responses.Add(re));
 
 // ....
 cmd.CancelAndJoin(); //stops the interface monitoring
Enjoy,
D
btw i have another question how to make this code
 ITikCommand cmdhotspot = conn.CreateCommand("/ip/hotspot/user/disable",
                                   conn.CreateParameter(".id", IserverHotspot._IDUser));
be static function that include on tik4net.objects , so if i want disable hotspot user i only call command like this
var listdisableduserwifi = conn.LoadList<HotspotUser>().Where(p => p.Name == IserverHotspot._NameUser).SingleOrDefault();
 listdisableduserwifi.Disableduser();
and same when i will enabled the hotspot user..

and what should i do for adding userman object to tik4net.object ?
is it add the folder into tik4net.object and add userman.cs , without add some note for tell the visual studio project that i add new object on related project...

thanks for your time dhani , i hope you will answer it...
 
User avatar
danikf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Mon Mar 14, 2011 8:57 am

Re: C# API - tik4net on GitHub

Fri Jul 08, 2016 5:46 pm

Hi all,

version 2.1.0.0 (just .NET 4.6 support added) has been published (github/nuget). I will publish binaries in this phorum as soon as the error with attachment upload will be fixed. In this time I just get "HTTP Error". Any idea?

Update 2016-07-16: dlls published (upload has been fixed)

Stay tuned,
D
Last edited by danikf on Sat Jul 16, 2016 11:15 am, edited 1 time in total.

Who is online

Users browsing this forum: No registered users and 7 guests