Community discussions

MikroTik App
 
geraldospint
just joined
Topic Author
Posts: 3
Joined: Fri Jun 19, 2009 11:54 pm

API - ACL Control

Sat Jun 20, 2009 4:44 pm

How to send this command to the router using API

/interface wireless access-list remove [find comment=teste]

Thanks

geraldo@spint.com.br
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Sat Jun 20, 2009 7:48 pm

first, you should get .id's of that entry:
/interface/wireless/access-list/print
.proplist=.id
?comment=teste
then remove all items found
/interface/wireless/access-list/remove
=.id=<your_id_here>
and, AFAIR, you may use comma-separated list of ids in <your_id_here>
 
geraldospint
just joined
Topic Author
Posts: 3
Joined: Fri Jun 19, 2009 11:54 pm

Re: API - ACL Control

Wed Jun 24, 2009 6:34 pm

I need dynamically as:
/interface/wireless/access-list/remove=
.id=</interface/wireless/access-list/print
.proplist=.id
?comment=teste>

is possible ?
 
ayufan
Member
Member
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: API - ACL Control

Wed Jun 24, 2009 8:13 pm

no, first you have to getall items
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Wed Jun 24, 2009 11:10 pm

do you ask, whether it's possible to join API queries? no, it's not. simply execute one query, then use its result for the second one. what's problem?
 
juanCasseus
just joined
Posts: 15
Joined: Mon Jul 20, 2009 12:02 am

Re: API - ACL Control

Fri Jul 24, 2009 1:37 am

HI,,
I Understan all to remove, what I dont understand is when you say <your_id_here>

/interface/wireless/access-list/print
.proplist=.id
?comment=teste ******* isnot ?=comment=teste
/interface/wireless/access-list/remove
=.id=<your_id_here> ****What mean <your_id_here> What exactly Do I have to put

Thanks
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Fri Jul 24, 2009 9:24 am

first, you execute
/interface/wireless/access-list/print
=.proplist=.id
?comment=teste
"?comment=teste" is short form of "?=comment=teste"

in response, you receive something like
!re=
=.id=*4EB
and then you can delete this entry:
/interface/wireless/access-list/remove
=.id=*4EB
is it clear enough?..
 
mknnoc
Trainer
Trainer
Posts: 229
Joined: Thu Feb 28, 2008 6:40 am
Location: cambodia

Re: API - ACL Control

Sat Nov 07, 2009 4:56 am

can you please write the complete code?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Sat Nov 07, 2009 1:29 pm

complete code of what? it was already done in my prevoius post, no? =)
 
User avatar
Arcanjo
just joined
Posts: 5
Joined: Sat Nov 07, 2009 11:02 pm
Location: Abadiânia-GO

Re: API - ACL Control

Sat Nov 07, 2009 11:08 pm

Hi, im new in this forum. Sorry my English :?

I have try make this example code to start learn Mikrotik API and I get de fallow message:
Connected...
<<< [22] /ip/hotspot/user/print
<<< [14] =.proplist=.id
<<< [14] ?comment=teste
>>> [5/5 bytes read.
>>> [5, 32] !trap
>>> [23/23 bytes read.
>>> [23, 8] =message=argument error
>>> [5/5 bytes read.
>>> [5, 1] !done
<br /> 
<b>Notice</b>:  Undefined offset: 0 in <b>C:\wamp\www\api\teste2.php</b> on line <b>17</b><br /> 
testefsfs<<< [20] /ip/hotspot/user/set
<<< [5] =.id=
<<< [13] =disabled=yes
>>> [5/5 bytes read.
>>> [5, 1] !done
Disconnected...
My Code:
if ($API->connect('xxx', 'xxx', 'xxx')) {

$API->write('/ip/hotspot/user/print',false);
$API->write('=.proplist=.id',false);
$API->write('?comment=teste');


$A = $API->read();
$A = $A[0];

  echo "testefsfs".$A;

$API->write('/ip/hotspot/user/set',false);
$API->write('=.id='.$A['.id'],false);
$API->write('=disabled=yes');
$API->read();

   $API->disconnect();
Thanks!!
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Sun Nov 08, 2009 3:48 am

what version of RouterOS?
 
User avatar
Arcanjo
just joined
Posts: 5
Joined: Sat Nov 07, 2009 11:02 pm
Location: Abadiânia-GO

Re: API - ACL Control

Sun Nov 08, 2009 5:13 am

v3.13
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Sun Nov 08, 2009 1:42 pm

queries (starting with '?') appeared only in the v3.21. not sure about '.proplist'. so you should upgrade
 
User avatar
Arcanjo
just joined
Posts: 5
Joined: Sat Nov 07, 2009 11:02 pm
Location: Abadiânia-GO

Re: API - ACL Control

Mon Nov 09, 2009 3:01 pm

Thanks Chupaka

So I need update de Router O.S. I,m afraid to do this becouse my server is run 100% whit this version 3.13.

May be I have to try a Telnet commands on my APP and forget mikrotik API :(

Thanks
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Mon Nov 09, 2009 6:14 pm

update it. if something goes wrong, you can downgrade to 3.13 again =)
 
User avatar
Arcanjo
just joined
Posts: 5
Joined: Sat Nov 07, 2009 11:02 pm
Location: Abadiânia-GO

Re: API - ACL Control

Tue Nov 10, 2009 1:22 am

I will Take courage. Just in that RB I have up to 200 users lol

Maybe buy a less expensive RB411 just for test. Yes, in Brazil every think is too expensive lol
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Tue Nov 10, 2009 9:50 am

I have a router with up to 600 online users - I update it at night ;)
 
User avatar
Arcanjo
just joined
Posts: 5
Joined: Sat Nov 07, 2009 11:02 pm
Location: Abadiânia-GO

Re: API - ACL Control

Wed Nov 11, 2009 1:14 am

Is possible take a same result with Telnet or SSH and PHP?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Wed Nov 11, 2009 10:32 am

/ip hotspot user set [find comment="teste"] disabled=yes
 
User avatar
sky_16
just joined
Posts: 20
Joined: Wed Nov 15, 2006 4:36 am

Re: API - ACL Control

Fri Nov 20, 2009 3:58 pm

is there any visual basic 6 class for mikrotik API? or sample maybe?
@chupaka => would you mind give some example using visual basic 6 to build a class for mikrotik API?
is it possible communicate to router API port (8728) using winsock control in visual basic 6

thanks
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Sat Nov 21, 2009 5:14 pm

sure you can use Winsock. unfortunately, I haven't see any VB6 API implementations here...

try to look at C# client - maybe it can help a bit
 
hrodriguesvt
just joined
Posts: 18
Joined: Tue Mar 03, 2009 1:58 pm

Re: API - ACL Control

Wed Mar 31, 2010 11:24 pm

Hi Folks,

I've been trying several ways to put this working, but i simply cant find where is my error.

I would like to disconnect the active user from hotspot, using PHP API.

We use routeros 3.2 in some systems and 4.5 in other ones.

I REALLY apreciate your help!


My current code is:

require('routeros_api.class.php');
$API = new routeros_api();
$API->debug = true;

if ($API->connect('1.2.3.4', 'host', 'pass')) {

$varlogin = "TESTLOGIN";

$API->write('/ip/hotspot/active/print', false);
$API->write('=.proplist=.id', false);
$API->write('?user='.$varlogin);

$varloginid = $API->read();
$varloginid = $A[0];

$API->write('/ip/hotspot/active/remove', false);
$API->write('=.id='.$varloginid);

$API->read();

$API->disconnect();

}
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: API - ACL Control

Thu Apr 01, 2010 9:29 am

from the first look it should work on newer systems. As you can read above queries was introduced later on than some of your installations.
 
hrodriguesvt
just joined
Posts: 18
Joined: Tue Mar 03, 2009 1:58 pm

Re: API - ACL Control

Mon Apr 05, 2010 8:31 pm

from the first look it should work on newer systems. As you can read above queries was introduced later on than some of your installations.
Buddy, i've tried to use the same commands on ROS 3.2 and ROS4.5, none of them worked
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26385
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: API - ACL Control

Tue Apr 06, 2010 12:16 pm

from the first look it should work on newer systems. As you can read above queries was introduced later on than some of your installations.
Buddy, i've tried to use the same commands on ROS 3.2 and ROS4.5, none of them worked
what didn't work?
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: API - ACL Control

Tue Apr 06, 2010 2:23 pm

exactly. It would be greate to see the output you got when you executed that php api.

proplist and queries was introduced only in later version 3 releases. that is, 3.30 have proplist, older may not.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Sun Apr 11, 2010 2:45 am

yep, check your $varloginid variable...
 
User avatar
Chofex
Member Candidate
Member Candidate
Posts: 141
Joined: Mon Mar 27, 2006 7:03 am
Location: San Rafael, Mendoza, Argentina

Re: API - ACL Control

Tue May 18, 2010 4:41 am

Did you get lucky with API and Visual Basic 6 ?
I'd REALLY appreciate if someone could tell me how to connect using VB6 to RouterOS API...
I don't mind paying for a component (something reasonable, please!)

I program using VB since 1993, and I use VB 6 every day at job. I've developed an ERP form my ISP also, and it would be very helpfull to connect it to my HotSpot!

Thanks in advance!

Chofex
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: API - ACL Control

Wed Dec 08, 2010 8:57 pm

can you please write the complete code?

I think you want this:

http://forum.mikrotik.com/viewtopic.php?f=13&t=47274

Here you see what do you put in <your_id_here>. Perhapes you need a list of id. So look this link...
 
rpayan
just joined
Posts: 5
Joined: Thu Sep 15, 2016 10:30 am

How Edit a User

Thu Sep 15, 2016 10:37 am

Hello Everibody.

I'm using the version 6.x but I cant edit a user from API with c#. Can you help me.
Here is my code:

mikrotik.Send("/ip/hotspot/user/print", false);
mikrotik.Send("name=" + item.usuarioTicket, false);
mikrotik.Send("=.proplist=.id");
List<string> test = mikrotik.Read();
var x = test[0].Split('=');

mikrotik.Send("/ip/hotspot/user/set");
mikrotik.Send("=comment=killed");
mikrotik.Send("=.id=" + x[2].ToString(),true); //Here the index 2 correspond to my .id
mikrotik.Read();
mikrotik.Close();
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Thu Sep 15, 2016 3:42 pm

and what message do you receive in response to the last request?

mikrotik.Send("/ip/hotspot/user/set");
mikrotik.Send("=comment=killed");
should be
mikrotik.Send("/ip/hotspot/user/set", false);
mikrotik.Send("=comment=killed", false);
I think :)
 
rpayan
just joined
Posts: 5
Joined: Thu Sep 15, 2016 10:30 am

Re: API - ACL Control

Thu Sep 15, 2016 6:53 pm

Nothing :(

I get the full data in my variable test : !re=.id=*6=name=Juli26=password=EwMnI=profile=NITE=limit-uptime=1w23h59m40s=uptime=1h55m42s=bytes-in=1912229=bytes-out=1343304=packets-in=5843=packets-out=4392=dynamic=false=disabled=false=comment=life

So in this case x[2].ToString() correspond to *6, but I cant change the comment :(


mikrotik.Send("/ip/hotspot/user/print", false);
mikrotik.Send("name=" + item.usuarioTicket, false);
mikrotik.Send("=.proplist=.id");
List<string> test = mikrotik.Read();
var x = test[0].Split('=');

mikrotik.Send("/ip/hotspot/user/set",false);
mikrotik.Send("=.id=" + x[2].ToString(), false);
mikrotik.Send("=comment=vencido", true);

mikrotik.Read();
mikrotik.Close();
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Thu Sep 15, 2016 7:00 pm

--- mikrotik.Read();
+++ List<string> test2 = mikrotik.Read();
and see what's in test2
 
rpayan
just joined
Posts: 5
Joined: Thu Sep 15, 2016 10:30 am

Re: API - ACL Control

Thu Sep 15, 2016 7:09 pm

test2 shows : "!trap=message=no such command prefix"
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Thu Sep 15, 2016 8:09 pm

well, "/ip/hotspot/user/set" looks fine and works for me as a command :) maybe a typo in your actual code?..
 
rpayan
just joined
Posts: 5
Joined: Thu Sep 15, 2016 10:30 am

Re: API - ACL Control

Fri Sep 16, 2016 10:45 pm

Thank So much
I got this works...

mikrotik.Send("/ip/hotspot/user/set");
mikrotik.Send("=comment=vencido");
mikrotik.Send("=.id=" + userName, true);
 
rpayan
just joined
Posts: 5
Joined: Thu Sep 15, 2016 10:30 am

CALL SCRIPT FROM API

Fri Sep 16, 2016 10:55 pm

How could I call and run a script from API ??
I was trying this but doesnt work.

mikrotik.Send("/system/script/run", false);
mikrotik.Send("=name=nameScript", true);
mikrotik.Read();
mikrotik.Close();

I got in the Read... no such commad prefix
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API - ACL Control

Mon Sep 19, 2016 2:59 pm

something strange again, just like the last time. this command DOES exist :)
/system/script/run
=.id=script1
!done
=ret=Hello, I'm a script! And this is my output

Who is online

Users browsing this forum: Google [Bot] and 84 guests