To make the setup process faster I writting c# Winforms Application base on you tik4net API call Mikrotik Controller right now.
When you reset no default the Mikrotik router(951Ui), it IP will become “0.0.0.0”.
So there is no other way for me to configure the router via MAC address.
Any solution for me, thank you so much.
Hi,
I really need help on this bit of code.
ITikCommand printcmd = connection.CreateCommand("/ip/ipsec/remote-peer/print");
IEnumerable<ITikReSentence> userlist = printcmd.ExecuteList();
Running it will return Exception: ‘no such command prefix’
What have I done wrong?
/ip/ipsec/remote-peer is not valid.
/ip/ipsec/remote-peers is.
wow. Of all this time I ran that command without ‘s’.
Terminal is much more forgiving than API huh? ![]()
Feeling very silly now.
Thank you. You’ve been a GREAT help. ![]()
Hi,
what are you meaning by “ip binding object”. Is it different from IpAddress object?
D
Hi,
mac-telnet is complicated protocol - I have tried to find some libraries, but without success (.NET libraries
). Not sure, but you can try to manage it by connection to neigbor router and use its mac-telnet function …
Sorry, but I don’t have any better solution …
D
After that little incident with missing ‘s’, I was humming along just fine.
However, while performing disconnection on one connection made by Android phone program failed and returned Exception.
See below.
Unhandled Exception: tik4net.TikSentenceException: Duplicit key ‘port’ with deffirent values ‘4500’ vs. ‘59061’
at tik4net.Api.ApiSentence..ctor(IEnumerable1 words) at tik4net.Api.ApiConnection.ReadSentence() at tik4net.Api.ApiConnection.GetOne(String tag) at tik4net.Api.ApiConnection.<GetAll>d__60.MoveNext() at System.Collections.Generic.List1.AddEnumerable(IEnumerable1 enumerable) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at tik4net.Api.ApiConnection.CallCommandSync(String commandRows)
at tik4net.Api.ApiCommand.ExecuteSingleRow()
First line of the exception talks about 4500 vs 59061
It turns out 4500 is the local port and 59061 is the remote port.
See below.
[admin@] > /ip ipsec remote-peers print detail
Flags: R - responder, N - natt-peer
0 RN id=“blah” local-address=X.X.X.X port=4500
remote-address=Y.Y.Y.Y port=59061 state=established
side=responder dynamic-address=172.29.58.92 uptime=46s last-seen=46s
Now, What I’m wondering is.. why on earth would this cause exception such as above?
Duplicate key with different value?
So I went back and looked at the ones I was able to disconnect successfully and for those ones two of the local and remote ports were both reading 4500.
See below.
[admin@] > /ip ipsec remote-peers print detail
Flags: R - responder, N - natt-peer
0 RN id=“blah” local-address=X.X.X.X port=4500
remote-address=Y.Y.Y.Y port=4500 state=established side=responder
uptime=7m20s last-seen=1m19s
Now, I don’t think I can do anything about Android phone using different remote port so how should I handle this case from the code?
In case any one wondering what caused that execption,
ITikReSentence id = connection.CreateCommandAndParameters("/ip/ipsec/remote-peers/print", "id", username).ExecuteSingleRow();
xxxxxxx/print command returns more than one =port=xxxx row in one !re sentence (this behavior was not expected and also not supported).
IMHO problem is, that there are two “port” fields - same name, different values. Works somehow because of their order …
I would preffer this “stupid” behavior to be fixed by mikrotik guys (e.q. local-port, remote-port), but workaround could be also implemented in tik4net core - It will return port and port2 in this case.
Issue: https://github.com/danikf/tik4net/issues/51
Workarounded in dev branch: https://github.com/danikf/tik4net/commit/f013745f166cc7ef5fa660598485891cf91e24dd
As workaround (if you don’t need port values) you can use .proplist filter (see API specification on mikrotik wiki) to return subset of fields you need.
D
Thank you for the workaround. I didn’t try the dev version of the api since proplist did the job.
BTW, Is there document on how to go about using the dev version?
Would this be possible with nuget?
Hi,
just download sources from github (Git clone or *.zip download), reference them as projects and rebuild your application. This scenario is usefull for debuging non-trivial problems and also for understandig how tik4net works inside
All code updates (an usually new tik object classes) can be pushed back to the main branch via pull request feature …
https://help.github.com/articles/cloning-a-repository/
D
Hello, Why this error?
Exception in System.Net.Sockets.SocketException
No connection could be made because the target machine actively refused it 12.12.12.1:8728
Your router is not accepting api connections. Go to IP > Services and check if api is enabled. Also check firewall and add appropriate input rule, e.g.:
/ip firewall filter
add chain=input dst-port=8728 in-interface-list=LAN protocol=tcp src-address=192.168.88.0/24
ip bindings from
ip/hotspot/ip-binding
Hello guys!
First of all, thanks a lot for author for such incredible API library.
Had any one problems with ApiSsl connection? 'TikConnectionType.Api' works fine, but if I try 'TikConnectionType.ApiSsl' I have exception like this:
System.Security.Authentication.AuthenticationException
HResult=0x80131501
Message=Failed to call SSPI, see the internal exception
Source=tik4net
Arborescence des appels de procédure :
at tik4net.Api.ApiConnection.Open(String host, Int32 port, String user, String password) dans D:\Downloads\tik4net-master\tik4net-master\tik4net\Api\ApiConnection.cs :line 182
at tik4net.Api.ApiConnection.Open(String host, String user, String password) dans D:\Downloads\tik4net-master\tik4net-master\tik4net\Api\ApiConnection.cs :line 148
at tik4net.ConnectionFactory.OpenConnection(TikConnectionType connectionType, String host, String user, String password) dans D:\Downloads\tik4net-master\tik4net-master\tik4net\ConnectionFactory.cs :line 49
at tik4net.tests.ConnectionTest.OpenConnectionWillNotFail() dans D:\Downloads\tik4net-master\tik4net-master\tik4net.tests\ConnectionTest.cs :line 17
Internal exception: The received message was unexpected or incorrectly formatted
I googled problem and find several solutions, but no one works in my case. Any help will be appreciated. Thanks a lot.
Is your mikrotik router properly configured? Which version of routeros do you use?
https://github.com/danikf/tik4net/wiki/SSL-connection
D
Is your mikrotik router properly configured? Which version of routeros do you use?
https://github.com/danikf/tik4net/wiki/SSL-connection
D
Hello! Thank you very much, all is working fine! Have a nice day! ![]()
ip bindings from
ip/hotspot/ip-binding
Here you are (and also commited in dev branch).
Enjoy,
D
namespace tik4net.Objects.Ip.Hotspot
{
/// <summary>
/// ip/hotspot/ip-binding
///
/// IP-Binding HotSpot menu allows to setup static One-to-One NAT translations, allows to bypass specific HotSpot clients without any authentication, and also allows to block specific hosts and subnets from HotSpot network
/// </summary>
[TikEntity("ip/hotspot/ip-binding")]
public class HotspotIpBinding
{
/// <summary>
/// .id: primary key of row
/// </summary>
[TikProperty(".id", IsReadOnly = true, IsMandatory = true)]
public string Id { get; private set; }
/// <summary>
/// address: The original IP address of the client
/// </summary>
[TikProperty("address", DefaultValue = "")]
public string/*IP Range*/ Address { get; set; }
/// <summary>
/// mac-address: MAC address of the client
/// </summary>
[TikProperty("mac-address", DefaultValue = "")]
public string/*MAC*/ MacAddress { get; set; }
/// <summary>
/// server
/// Name of the HotSpot server.
/// all - will be applied to all hotspot servers
/// </summary>
[TikProperty("server", DefaultValue = "all")]
public string/*string | all*/ Server { get; set; }
/// <summary>
/// to-address: New IP address of the client, translation occurs on the router (client does not know anything about the translation)
/// </summary>
[TikProperty("to-address", DefaultValue = "")]
public string/*IP*/ ToAddress { get; set; }
/// <summary>
/// type
/// Type of the IP-binding action
/// regular - performs One-to-One NAT according to the rule, translates address to to-address
/// bypassed - performs the translation, but excludes client from login to the HotSpot
/// blocked - translation is not performed and packets from host are dropped
/// </summary>
[TikProperty("type", DefaultValue = "")]
public string/*blocked | bypassed | regular*/ Type { get; set; }
}
}
Hi, Danik
im strugling to get into 1 router from another would you mind telling me what im doing wrong?
ITikConnection initconnection = ConnectionFactory.CreateConnection(TikConnectionType.Api);
initconnection.Open(“10.255.107.2”, “admin”, xxxx");
ITikCommand mac_telnetCmd = initconnection.CreateCommand(“/tool/mac-telnet”,
initconnection.CreateParameter(“host”, “64:D1:54:22:71:37”),
initconnection.CreateParameter(“Login”, “admin”),
initconnection.CreateParameter(“Password”, “xxxx”));
initconnection.CreateCommand(“/ip/address/add/”,
initconnection.CreateParameter(“address”, “192.168.9.1/24”),
initconnection.CreateParameter(“network”, “192.168.8.0”),
initconnection.CreateParameter(“interface”, “wlan2”));
Sorry, this is an unsupported feature:
https://wiki.mikrotik.com/wiki/API_command_notes#Interactive_commands
interactive command examples that will not work in API are:
/system telnet
/system ssh
/tool mac-telnet