Page 1 of 1
Re: API Links
Posted: Mon Jun 01, 2015 1:29 am
by luan
Hi folks.
I need to print on a table id and the name of the hostpot users.
and remove the User by his id.
Can anyone help me.
I use C Sharp
Re: API Links
Posted: Mon Jun 01, 2015 2:02 pm
by Chupaka
Hi folks.
I need to print on a table id and the name of the hostpot users.
and remove the User by his id.
Can anyone help me.
/ip/hotspot/user/print
=.proplist=.id,name
then
/ip/hotspot/user/remove
=.id=ID_HERE
I use C Sharp
http://wiki.mikrotik.com/wiki/API_in_C_Sharp
Re: API Links
Posted: Sat Jun 13, 2015 6:11 pm
by kgninfos
can anyone post a sample project with source on how to use the api in Android app
a simple /ip/address/print with parsing and show the result in textfeild/ table would be enough
Thanks
Re: API Links
Posted: Fri Aug 28, 2015 1:01 am
by danikf
Hi all,
please redirect link for tik4net (.NET (C#) - external by danikf) to new location (both in this thread and in wiki links).
New location of tik4net project:
https://github.com/danikf/tik4net
And newly created thread here:
http://forum.mikrotik.com/viewtopic.php?f=9&t=99954
Thanks,
D
Re: API examples
Posted: Thu Nov 05, 2015 9:02 pm
by nuclide
Can anybody make the API for VB (for VB projects and ASP pages)?!
Thanks,
Mladen
It will be wonderful
Re: API Links
Posted: Sun Nov 08, 2015 6:41 pm
by danikf
Hi,
why not use C# (.NET) dlls in VB (also .NET) code?
D
Re: API Links
Posted: Thu Jul 21, 2016 11:34 pm
by andredossantos
Implementation in Go (Golang):
https://github.com/go-routeros/routeros
To install, run:
go get gopkg.in/routeros.v1
Re: API Links
Posted: Fri Jul 22, 2016 1:55 pm
by andredossantos
Added Go implementation page to the wiki.
Could someone link to it from the API page?
http://wiki.mikrotik.com/wiki/API_in_Go
Re: API Links
Posted: Fri Jan 20, 2017 4:06 pm
by janisk
Added,
we really appreciate your input. Hopefully, a lot of our users will find this useful.
Re: API Links
Posted: Sun Nov 26, 2017 6:50 pm
by igorvukotic
Hi guys, need help with API/Python27
i follow:
https://wiki.mikrotik.com/wiki/Manual:A ... d_examples
can someone show how to pass this terminal command true API:
/ip firewall filter
add action=drop chain=input dst-port=53 in-interface=ether1_WAN protocol=udp
i tried ( with many variations ):
apiros.runCommand("/ip/firewall/filter/add","=chain=input\n=action=drop\n=dst-port=53\n=in-interface=ether1_WAN\n=protocol=udp","")
Re: API Links
Posted: Mon Nov 27, 2017 8:36 am
by Chupaka
.runCommand? I can't find this on the page you linked to...
Re: API Links
Posted: Mon Nov 27, 2017 11:04 am
by igorvukotic
class APIError(Exception):
def __init__(self, message, category = -1):
self.message = message
self.category = category
def __str__(self):
return repr(self.message)
class ApiRos:
"""
Routeros api
"""
def __init__(self, ip):
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sk.connect((ip, 8728))
self.sk = sk
self.currenttag = 0
def login(self, username, pwd):
for _, attrs in self.talk(["/login"]):
chal = binascii.unhexlify(attrs['=ret'])
md = md5.new()
md.update('\x00')
md.update(pwd)
md.update(chal)
self.talk(["/login", "=name=" + username,
"=response=00" + binascii.hexlify(md.digest())])
def talk(self, words):
if self.writeSentence(words) == 0:
return
r = []
while 1:
i = self.readSentence();
if len(i) == 0:
continue
reply = i[0]
attrs = {}
for w in i[1:]:
j = w.find('=', 1)
if (j == -1):
attrs[w] = ''
else:
attrs[w[:j]] = w[j + 1:]
r.append((reply, attrs))
if reply == '!done':
return r
def writeSentence(self, words):
ret = 0
for w in words:
self.writeWord(w)
ret += 1
self.writeWord('')
return ret
def readSentence(self):
r = []
while 1:
w = self.readWord()
if w == '':
return r
r.append(w)
def writeWord(self, w):
# print "<<< " + w
self.writeLen(len(w))
self.writeStr(w)
def readWord(self):
ret = self.readStr(self.readLen())
# print ">>> " + ret
return ret
def writeLen(self, l):
if l < 0x80:
self.writeStr(chr(l))
elif l < 0x4000:
l |= 0x8000
self.writeStr(chr((l >> 8) & 0xFF))
self.writeStr(chr(l & 0xFF))
elif l < 0x200000:
l |= 0xC00000
self.writeStr(chr((l >> 16) & 0xFF))
self.writeStr(chr((l >> 8) & 0xFF))
self.writeStr(chr(l & 0xFF))
elif l < 0x10000000:
l |= 0xE0000000
self.writeStr(chr((l >> 24) & 0xFF))
self.writeStr(chr((l >> 16) & 0xFF))
self.writeStr(chr((l >> 8) & 0xFF))
self.writeStr(chr(l & 0xFF))
else:
self.writeStr(chr(0xF0))
self.writeStr(chr((l >> 24) & 0xFF))
self.writeStr(chr((l >> 16) & 0xFF))
self.writeStr(chr((l >> 8) & 0xFF))
self.writeStr(chr(l & 0xFF))
def readLen(self):
c = ord(self.readStr(1))
if (c & 0x80) == 0x00:
pass
elif (c & 0xC0) == 0x80:
c &= ~0xC0
c <<= 8
c += ord(self.readStr(1))
elif (c & 0xE0) == 0xC0:
c &= ~0xE0
c <<= 8
c += ord(self.readStr(1))
c <<= 8
c += ord(self.readStr(1))
elif (c & 0xF0) == 0xE0:
c &= ~0xF0
c <<= 8
c += ord(self.readStr(1))
c <<= 8
c += ord(self.readStr(1))
c <<= 8
c += ord(self.readStr(1))
elif (c & 0xF8) == 0xF0:
c = ord(self.readStr(1))
c <<= 8
c += ord(self.readStr(1))
c <<= 8
c += ord(self.readStr(1))
c <<= 8
c += ord(self.readStr(1))
return c
def writeStr(self, str):
n = 0;
while n < len(str):
r = self.sk.send(str[n:])
if r == 0: raise RuntimeError, "connection closed by remote end"
n += r
def readStr(self, length):
ret = ''
while len(ret) < length:
s = self.sk.recv(length - len(ret))
if s == '': raise RuntimeError, "connection closed by remote end"
ret += s
return ret
def getSocket(self):
return self.sk
def runCommand(self, command, cmd2, cmd3, **arguments):
'''
Run a command attempting to keep as close to the command line version,
while maintaining an easy to use library.
'''
apiMessage = [command, cmd2, cmd3]
if arguments != None:
apiMessage += ["={0}={1}".format(k.replace('__', '-'), v) for k, v in arguments.items()]
rez = self.talk(apiMessage)
# print rez
# Remove the !done at the end of the list.
if rez[len(rez) - 1][0] == '!done':
doneVal = rez.pop()
# Check for error conditions (Need to make this more efficient).
trapVal = filter(lambda x: x[0] == '!trap', rez)
if trapVal != []:
trapVal = trapVal.pop()
if 'category' in trapVal:
category = trapVal[1]['=category']
else:
category = -1
# print "TrapVal = {0}".format(trapVal[1])
raise APIError(trapVal[1]['=message'], category)
# Extract the data itself
data = map(lambda x: x[1], rez)
if data == []:
if doneVal[1] != {}:
data = doneVal[1]['=ret']
return data
Re: API Links
Posted: Mon Nov 27, 2017 12:31 pm
by Chupaka
Try "dst__port=53\n=in__interface=ether1_WAN" (replace 'minus' sign with double underscore)
Re: API Links
Posted: Mon Nov 27, 2017 4:48 pm
by igorvukotic
no help..
Screen Shot 2017-11-27 at 15.46.31.jpg
Re: API Links
Posted: Tue Nov 28, 2017 12:35 pm
by Chupaka
I'm not familiar with Py, check this:
viewtopic.php?p=392367
Re: API Links
Posted: Fri Jun 22, 2018 8:10 pm
by lniconet
Hello,
For those interested, my python module to use the API:
https://github.com/lnicolas83/routeros-api
Re: API Links
Posted: Fri Jul 13, 2018 12:50 am
by SergeS
Does anybody need Labview code for Mikrotik API support?
If yes - I could share it. I wrote it and was using already for few years with good results.
If nobody - I will not bother...
Re: API Links
Posted: Tue Aug 14, 2018 11:07 pm
by Pulido
I'm definitely interested in seeing this. Thanks.
Re: API Links
Posted: Fri Mar 29, 2019 12:49 pm
by BlackVS
One more Python API (still beta but functional) :
https://github.com/BlackVS/smartROS (some
description in Russian)
Is developed for my own needs.
Main features:
- TLS+ADH / TLS+certificates connection supported
- routers' credentials stored in config file
- human readable conditions (see below)
- test script "console" included
Conditions in commands:
in console:
/ip/firewall/address-list/print where="list==Blacklist and address==8.8.8.8"
or in Python ( style 1):
import smartROS
router = smartROS.getRouter("Main")
print( router.ip.firewall.address__list.print (where="list==Blacklist and address==8.8.8.8") )
or in Python ( style 2):
import smartROS
router = smartROS.getRouter("Main")
print( router.do("/ip/firewall/address-list/print", where="list==Blacklist and address==8.8.8.8") )
Re: API Links
Posted: Wed May 15, 2019 9:50 pm
by Madnessy
Not really api related , nor scripting related.
But is there an ansible playbook somewhere we can use to configure our devices ?
(Already started building my own cause i could'nt find one on the ansible galaxy nor on the forum)
Re: API Links
Posted: Thu May 23, 2019 11:20 pm
by nar6du14
This a link to a python 3 asynchronous version of mikrotik api feel free to share it
https://bitbucket.org/wambedu14/splynxp ... krotik_api
Re: API Links
Posted: Wed May 29, 2019 11:01 am
by Madnessy
made a first commit of the ansible role / playbook
https://github.com/Madnessy/ansible-mikrotik
feel free to use / test / share / suggest improvements etc
Re: API Links
Posted: Fri Sep 06, 2019 1:09 pm
by arielf
Hello, does anyone know or have any php, that helps me to add, delete, block, leasess of the dhcp-server mikrotik?
Re: API Links
Posted: Fri Jan 03, 2020 7:31 pm
by Longsdale
I have written a C++ API connector/wrapper:
https://github.com/zx2512/MikrotikPlus
It would be nice if this gets added to these lists as there is no other good C++ connector available.
Re: API Links
Posted: Sat Jan 04, 2020 1:54 pm
by Chupaka
It supports only RouterOS versions 6.43 and later, right?
Re: API Links
Posted: Sat Jan 04, 2020 4:01 pm
by Longsdale
It supports only RouterOS versions 6.43 and later, right?
That is correct. I didn't want to bother with the outdated authentication method which is removed in the latest versions.
Re: API Links
Posted: Sat Jan 04, 2020 6:43 pm
by legrang
Supporting both is not difficult
Re: API Links
Posted: Sat Jan 04, 2020 6:46 pm
by Longsdale
Supporting both is not difficult
I didn't really want to spend additional time on it. Updating consumes less time.
Re: API Links
Posted: Sat Apr 11, 2020 4:46 pm
by vasilevkirill
hi,
this simple GUI for testing RouterOS API, based in web browser.
need running binary and open
http://localhost:8081
source
https://github.com/vasilevkirill/RouterOSAPIGUI
binary for all platforms
https://github.com/vasilevkirill/Router ... I/releases
Re: API Links
Posted: Mon Jul 27, 2020 4:49 pm
by arsalansiddiqui
I want to get logs in pagination and dhcp lease in pagination what should i do to make output to a certain limit, example 1 to 10 or 67 to 87.
I'm using PHP api of Denis Basta
Re: API Links
Posted: Fri Jul 31, 2020 11:16 am
by Chupaka
You just get full list via API and then sort/paginate as you want.
Re: API Links
Posted: Sat Aug 01, 2020 9:04 pm
by arsalansiddiqui
If i fetch full page than what's use of pagination then, pagination helps to load only certain records thats what i want. i dont want to load all records its no use, i want to minimize the delay time faced during full fetched data
Re: API Links
Posted: Mon Aug 03, 2020 10:01 am
by mrz
API does not support such feature. You can only use queries to filter returned items by specific criteria, but no paging.
Re: API Links
Posted: Sat Aug 29, 2020 11:56 am
by James56
Note: The PHP links in the top post don't work.
Re: API Links
Posted: Mon Aug 31, 2020 4:02 pm
by Chupaka
13:51, 3 January 2019 Normis (talk | contribs) deleted page RouterOS PHP class
13:51, 3 January 2019 Normis (talk | contribs) deleted page API PHP class
But some other API articles are still in Wiki... Normis?..
I'll update the first post with a link to
https://github.com/BenMenking/routeros-api and will wait for the answer in
viewtopic.php?p=814209#p814209 - the repo there is not available for me now.
Re: API Links
Posted: Fri Oct 02, 2020 6:59 pm
by alqadhi
How do I submit a library to be included in the Wiki?
Here is a library that I wrote a few months ago. It is written in C++17, and uses Boost.Asio (will be included in the C++23 standard).
https://github.com/aymanalqadhi/tikpp
Re: API Links
Posted: Sat Oct 17, 2020 8:23 pm
by alqadhi
Please update the post with the last library in the
Wiki API page.
Re: API Links
Posted: Sun Oct 18, 2020 10:58 pm
by Chupaka
Added a link to the first post
Re: API Links
Posted: Fri Mar 19, 2021 12:07 pm
by Manfi99
Does anybody need Labview code for Mikrotik API support?
If yes - I could share it. I wrote it and was using already for few years with good results.
If nobody - I will not bother...
Hello,
I am interested in your LabVIEW code. Could you share it to me, please?
Thank you very much.
Re: API Links
Posted: Sun Apr 25, 2021 10:29 am
by jeppu31
Looking for Mikrotik api for Arduino using esp32, esp8266 please share it to me or email me jeffcastaneda31@ gmail. com
Thanks.. Godbless
Re: API Links
Posted: Sat May 01, 2021 1:34 am
by Chupaka
There are clients for C and C++ - just use them?..
Re: API Links
Posted: Thu Aug 12, 2021 5:08 pm
by Electrogics
Hi, where is the wiki for API C? it seems to be moved, I can't access, thank you!
API support for command concatenation?
Posted: Wed May 04, 2022 6:22 pm
by Larsa
Anyone who knows a API framework that supports command concatenation or command substitution aka “[]” or "()" ? We've tried some frameworks for python, perl, php and javascript but found nada so far.
Could it be the implementations that is limited or even worse a restriction in the core API itself?
Re: API Links
Posted: Tue May 10, 2022 4:02 pm
by Chupaka
What exactly do you want to do by "command concatenation or substitution"?..
Re: API Links
Posted: Sun May 22, 2022 2:18 pm
by msatter
Re: API Links
Posted: Wed Aug 17, 2022 11:26 pm
by wesllycode
Re: API Links
Posted: Fri Aug 19, 2022 5:18 pm
by anav
Question from a non techie..... What is an API...
APIs let your product or service communicate with other products and services without having to know how they’re implemented.
Okay, so not much further ahead other than its some sort of, in my experience, ICD (interface control document which details the inputs and outputs of data and their formats at an interface so that two systems communicating can be programmed to accept and provide data in the agreed to formats).
This appears similar to API, so what are all the APIs being used for by folks here? Is it simply to program the MT routers from some other software?
Re: API Links
Posted: Fri Aug 19, 2022 5:23 pm
by rextended
Is just another protocol like HTTP...
No matter if IIS, Apache, nginx, etc., no matter if is etscape, opera, firefox, internet explorer...
Re: API Links
Posted: Sat Aug 20, 2022 3:19 pm
by saintmg
Hi, any API for PHP, JS or Python for hAP lite TC RB941-2nD-TC?
I wanted to create a hotspot management system so I can rent my Internet connection via WiFi. Thanks!
Re: API Links
Posted: Sun Aug 21, 2022 11:54 am
by BartoszP
Have you read
https://wiki.mikrotik.com/wiki/Manual:API ? Is it so hard to find that page? If yes, what could be done do make searching forum better instead of
search.php?keywords=api+links ? What's wrong with the topic itself
viewtopic.php?t=29073 ?
Re: API Links
Posted: Tue Aug 23, 2022 8:57 am
by atuxnull
i have a few queues and i would like to create a shortcurt to my desktop PC (Win 10) so i could enable/disable a particular queue, without user interaction.
I have basic programming training, nothing special. So even a bat file would do the trick. Is there a way to do this please?
Re: API Links
Posted: Sat Sep 17, 2022 2:47 pm
by Chupaka
i have a few queues and i would like to create a shortcurt to my desktop PC (Win 10) so i could enable/disable a particular queue, without user interaction.
I have basic programming training, nothing special. So even a bat file would do the trick. Is there a way to do this please?
SSH. Simply setup SSH access with key (instead of password, so you don't need to type it) - and you can run any command from .bat by simply executing something like
ssh admin@router_IP "/queue simple disable queue1"
Re: API Links
Posted: Sat Jan 14, 2023 9:29 pm
by FIBRANETPLUS
Hello, I need enable disable L2TP-Server
Any idea?
$API->write("/ppp/l2tp/disable",true); not work!
Re: API Links
Posted: Sat Jan 14, 2023 10:50 pm
by rextended
i do not know if /ppp/l2tp/ exist, but the command on terminal are:
/interface l2tp-server server set enabled=no
/interface l2tp-server server set enabled=yes
Re: API Links
Posted: Sun Jan 15, 2023 6:12 pm
by FIBRANETPLUS
i do not know if /ppp/l2tp/ exist, but the command on terminal are:
/interface l2tp-server server set enabled=no
/interface l2tp-server server set enabled=yes
thanks
$API->write("/interface/l2tp-server/server/getall",true);
response
<<< [36] /interface/l2tp-server/server/getall >>> [3/3] bytes read. >>> [3, 304]!re >>> [13/13] bytes read. >>> [13, 290]=enabled=true >>> [13/13] bytes read. >>> [13, 276]=max-mtu=1450 >>> [13/13] bytes read. >>> [13, 262]=max-mru=1450 >>> [14/14] bytes read. >>> [14, 247]=mrru=disabled >>> [36/36] bytes read. >>> [36, 210]=authentication=chap,mschap1,mschap2 >>> [21/21] bytes read. >>> [21, 188]=keepalive-timeout=30 >>> [23/23] bytes read. >>> [23, 164]=max-sessions=unlimited >>> [35/35] bytes read. >>> [35, 128]=default-profile=default-encryption >>> [14/14] bytes read. >>> [14, 113]=use-ipsec=yes >>> [26/26] bytes read. >>> [26, 86]=ipsec-secret=xxxxxxxxxx >>> [26/26] bytes read. >>> [26, 59]=caller-id-type=ip-address >>> [27/27] bytes read. >>> [27, 31]=one-session-per-host=false >>> [22/22] bytes read. >>> [22, 8]=allow-fast-path=false >>> [5/5] bytes read. >>> [5, 1]!done OkDisconnected...
I try
Disable
$API->write("/interface/l2tp-server/server/set",false);
$API->write("=enabled=false",true);
Enable
$API->write("/interface/l2tp-server/server/set",false);
$API->write("=enabled=true",true);
Work Fine, thanks
Re: API Links
Posted: Sun Jan 15, 2023 8:52 pm
by rextended
Work Fine, thanks