Page 1 of 1
Can i send a command as a parameter in microtik API
Posted: Wed Apr 03, 2013 9:21 pm
by siberia
Hi. i am testing the API interface i have developed through java API.
what i need is to send a command to change the ip address of a user.
actually i have to acomplish this work , sending to separate commands:
1) I send this command first to get the user id :
/ppp/secret/print
?name=smith
=.proplist=.id
it returnrs :
!re
=.id=*7
!done
2) next i have to send a command to change the ip to the returned id:
/ppp/secret/set
=.id=*7
=remote-address=10.12.10.50
so i want to know if there is a way to get this result in a single script ??
i tryed to change the ip using the name instead of the id but it din't work/
thanks regards !
Re: Can i send a command as a parameter in microtik API
Posted: Thu Apr 04, 2013 12:12 am
by boen_robot
Try
/ppp/secret/set
=numbers=smith
=remote-address=10.12.10.50
Re: Can i send a command as a parameter in microtik API
Posted: Thu Apr 04, 2013 12:42 am
by siberia
Smith.
thanks you very much. it worked !
do you got some reference where i can learn or find information about ppp commands that i can use with API.
thanks again.
Re: Can i send a command as a parameter in microtik API
Posted: Thu Apr 04, 2013 1:07 am
by boen_robot
API commands closely follow shell commands.
When you're at a terminal, type the command and then press "?" to see the arguments it can accept.
In terminal, you can omit the names of some arguments, but in API, you are required to specify all of them. If the name of an argument can be omitted in terminal, it will be surrounded with "<" and ">".
A typical argument for targeting entries is "numbers". The API version of this argument can accept anything its shell equivalent can except numbers (ironically enough), although it can accept an ID. So - if in terminal you can target an entry with something other than a number, you should be able to do the same from the API.
Re: Can i send a command as a parameter in microtik API
Posted: Thu Apr 04, 2013 1:28 am
by siberia
Good enough explanation.
thanks again man !
Re: Can i send a command as a parameter in microtik API
Posted: Tue Apr 09, 2013 11:14 pm
by rumiclord
Is there a way to input a user command during a script ?
example: -- [Q quit|D dump|C-z pause]
how do I tell the script to simulate the user pressing the q button to quit the current command?
Re: Can i send a command as a parameter in microtik API
Posted: Wed Apr 10, 2013 12:32 pm
by janisk
in CLI you cannot do anything else but run continuous command. However you can open new cli to continue work.
In API you can run multiple commands and use .tag to tag those, so you can run several and manage how long each of the runs. and what reply comes from what continuos command.
Re: Can i send a command as a parameter in microtik API
Posted: Wed Apr 10, 2013 6:07 pm
by siberia
H Janisk, excellent information.
can you give us some sample ?
tanks
Re: Can i send a command as a parameter in microtik API
Posted: Wed Apr 10, 2013 6:47 pm
by boen_robot
In terms of protocol flow, it might look something like:
/ping
=address=127.0.0.1
=.proplist=time
.tag=localhost
/ping
=address=192.168.0.100
=.proplist=time
.tag=admin
!re
.tag=localhost
=time=1ms
!re
.tag=admin
=time=1ms
!re
.tag=admin
=time=1ms
!re
.tag=localhost
=time=1ms
You'd have to inspect every reply from the getData() method, and see what it says after ".tag=".
Re: Can i send a command as a parameter in microtik API
Posted: Wed Apr 10, 2013 8:15 pm
by siberia
thanks
Re: Can i send a command as a parameter in microtik API
Posted: Wed Apr 17, 2013 6:44 pm
by SandroDIniz
API commands closely follow shell commands.
When you're at a terminal, type the command and then press "?" to see the arguments it can accept.
In terminal, you can omit the names of some arguments, but in API, you are required to specify all of them. If the name of an argument can be omitted in terminal, it will be surrounded with "<" and ">".
A typical argument for targeting entries is "numbers". The API version of this argument can accept anything its shell equivalent can except numbers (ironically enough), although it can accept an ID. So - if in terminal you can target an entry with something other than a number, you should be able to do the same from the API.
you have files dynamically in a page with PHP creation, modification and deletion of rules, settings MK web php
Re: Can i send a command as a parameter in microtik API
Posted: Wed Oct 31, 2018 9:45 pm
by rogeriomaciel
Could you please help me with a little code? I need to execute the command to change the name of MikroTik but I am not able to pass the parameters in the API in Swift. It's different from the PHP API. I've tried in many ways..
api.sendCommand(command: "/system/identity/set/name=TEST")
api.sendCommand(command: "/system/identity/set/=name=TEST")
api.sendCommand(command: "/system/identity/set\n=name=TEST")
...
As none of these worked, what would be the correct way to execute the commands passing parameters?
Thanks for the help.