danikf / tik4net

Manage mikrotik routers with .NET C# code via ADO.NET like API or enjoy O/R mapper like highlevel api.
Apache License 2.0
178 stars 94 forks source link

New API Login method needs documentation #64

Closed RavenWing71 closed 4 years ago

RavenWing71 commented 5 years ago

With RouterOS v6.45 out now, please document the change to Api_V2. If no where else, then here: https://github.com/danikf/tik4net/wiki/CRUD-examples-for-all-APIs. But a note on the Wiki front page would help those of us who already have working code that works no more.

raminrajabi commented 5 years ago

With New Release (6.45.6) I can't log in to MikroTik via API. the new API protocol is needed.

hkusulja commented 5 years ago

Also here same problem. Can not login using API and this NuGet after RouterOS update...

dominicusmento commented 5 years ago

Can someone write how we should connect now? ApiSsl, ApiSsl_v2? Is it still possible to connect by username and password?

danikf commented 5 years ago

ConnectionFactory.CreateConnection(TikConnectionType.Api_v2) is your friend ;-)

... will update WIKI soon ...

D

dominicusmento commented 5 years ago

@danikf Thanks for the fast reply. I tried TikConnectionType.Api_v2 already prior to writing here. The result is the same: 'invalid user name or password (6)'. using (ITikConnection connection = ConnectionFactory.OpenConnection(TikConnectionType.Api_v2, mikrotikGateway.Server, mikrotikGateway.Port, mikrotikGateway.Username, mikrotikGateway.Password)) User can login to winbox though. Are there any requirements special from the router side for this to work?

raminrajabi commented 5 years ago

I used the api_v2 and worked for me on Mikrotik 6.45.6

raminrajabi commented 5 years ago

ITikConnection connection;

  connection = ConnectionFactory.CreateConnection(TikConnectionType.Api_v2);
            connection.ReceiveTimeout = 5000;
            connection.SendTimeout = 5000;
            connection.Open(txtIP.Text, txtUsername.Text, txtPassword.Text);

            this.Text = Title + " - " + connection.ExecuteScalar("/system/identity/print");
dominicusmento commented 5 years ago

@raminrajabi thanks for the example. Unfortunately the result is the same as before. I even tried creating new user with full rights on router, still the same problem. RouterOs version is 6.45.6 too, nuget is latest, tik4net v3.4.0

danikf commented 5 years ago

Is API allowed in mikrotik configuration? (ip/services/api) Is API allowed from your machine? (IP filter in ip/services/api) Is API port accessible from the machine? (do you use the right port? default 8728) What about encoding? (exotic characters in username / password) Are you 100% sure you are connecting to the mikrotik router you expected?

dominicusmento commented 5 years ago

In the mikrotik log there are records like this: login failure for user 'X' from 'IP' via api I also checked if api is enabled, firewall etc. so answers would be: Yes Yes Yes only English characters are present in username/password, no encoding is set and needed Yes

danikf commented 5 years ago

Strange :/ last guess: Any ip subnet limitation on user or api service?

dominicusmento commented 5 years ago

Nope, no subnet limitations both on user and api service. Tried on another Mikrotik (test device) and this works like you've said. Before the RouterOs update it worked with both api and api_v2.. after the update on test device it doesn't work with api and it works ok with api_v2 TikConnectionType.. Strange but it is way it is.. Thanks for your help.

hkusulja commented 5 years ago

@tomidix it magically started working, so this is closed, right?

danikf commented 4 years ago

New version of login (back api and api_ssl) will work for both old and new version of mikrotik.