Chupak,It's my API client realization for Delphi7. It implements execution of parallel queries which are easily handled due to database-like interface.
v1.1: Added Delphi 2009 compatibility (thanks to Anton Ekermans for testing)
Wiki page: http://wiki.mikrotik.com/wiki/API_Delphi_Client
/interface/wireless/print
=.proplist=.id,hw-protection-mode
!re=
=.id=*6
=hw-protection-mode=none
/interface/wireless/set
=.id=*6
=hw-protection-mode=cts-to-self
!re=
=.id=*6
=hw-protection-mode=cts-to-self
mikrotik.Send("/interface/monitor-traffic");
mikrotik.Send("=interface=ether1");
mikrotik.Send("/cancel", true);
/ip/firewall/address-list/print','?list=mylist'
'ip/firewall/address-list/remove','=.id='+theid
please correct the docs: http://wiki.mikrotik.com/wiki/API#Command_descriptionfor details you have to use =detail= (not so old change)
if .proplist is absent, all possible properties are included, even those that have slow access time (such as file contents and perfomance counters). Thus use of .proplist is encouraged. Omission of .proplist may have high perfomance penalty.
arguments that modify list of returned properties (detail, breif, ...) have no effect in the API
ip hotspot active remove [/ip hotspot active find]
ip/hotspot/active/remove
=[=
=ip=
=hotspot=
=active=
=find=
=]=
first,how do I run this command because I have tried various ways and does not serve me.Code: Select allip hotspot active remove [/ip hotspot active find]
/ip/hotspot/active/print
=.proplist=.id
/ip/hotspot/active/remove
=.id=comma-separated-list-of-ids-from-prevoius-command-result
hmmm... maybe just disable HotSpot?..or can give me a help to disconnect all active users in hotspot
function Connect(const Hostname, Username, Password: AnsiString; const Port: AnsiString = '8728'): Boolean;
API and CLI (Terminal) are different things. in API, command should look like this:I wonder how do I include the following eating via api, this command works fine in terminal via mikrotik wimbox
/ queue / simple / add name = "Leonardo Xavier" target-addresses = "192.168.2.34"
max-limit = "256K/256K" burst-limit = "512K/512K" burst-threshold = "256K/256K" burst-time = "60/6
0 "
/queue/simple/add
=name=Leonardo Xavier
=target-addresses=192.168.2.34
=max-limit=256000/256000
=burst-limit=512000/512000
=burst-threshold=256000/256000
=burst-time=60/60
Function Tfrm_ApiConect.SendAndGetAll(ComandoCmd: TStrings): String;
var
Res: TRosApiResult;
pa: array of AnsiString;
i: Integer;
i2: Integer;
s: String;
begin
s := 'ERROR: Host unreachable.';
if TestServer(##### IP VALUE #####, ##### PORT VALUE #####)) then
begin
s := '';
SetLength(pa, 0);
for i := 0 to ComandoCmd.Count - 1 do
begin
s := Trim(ComandoCmd[i]);
if s <> '' then
begin
SetLength(pa, High(pa) + 2);
pa[High(pa)] := s;
end;
end;
if High(pa) >= 0 then
begin
Res := ROS.Query(pa, True)
end
else
begin
ShowMessage('Type a command!');
Exit;
end;
if ROS.LastError <> '' then
begin
s := ('ERROR: ' + ROS.LastError);
end;
while not Res.Eof do
begin
for i := 0 to High(Res.Values) do
s := s + Res.Values[i].Name + '=' + Res.Values[i].Value + #13#10;
s := s + '<END_INFO>'#13#10;
Res.Next;
end;
s := s + '================'#13#10;
s := Replace(s, #0, '#0');
Res.Free;
end;
Result := (s);
end;
Function TestServ(Host, Port: String): Boolean;
var
bCon: Boolean;
begin
bcon := False;
with TTcpClient.Create(nil) do
try
try
RemoteHost := Host;
RemotePort := Port;
Connect;
bCon := Connected;
except
end;
finally
if bCon then
begin
Disconnect;
Result := True;
end
else
begin
Connect;
bCon := Connected;
if bCon then
begin
Disconnect;
Result := True;
end
else
begin
Result := False;
end;
end;
Free;
end;
end;
var pa: array of AnsiString; i: Integer; begin SetLength(pa, 5); pa[0] := '/tool/user-manager/user/add'; pa[1] := '=customer=admin'; pa[4] := '=copy-from=*88'; for i := 100 to 199 do begin pa[2] := '=username=' + IntToStr(i); pa[3] := '=password=' + GetMyRandomPasswordFor(i); ROS.Query(pa, True).Free; // don't even try to check for errors - bad practice =] end;
your wayHow to check for existing user in user-manager?
/tool/user-manager/user/print
?name=115053253411
well, if you're not generating more than 1 user per second, you may use DateTimeToUnix(Now) for usernameAll of this will be useless if i'm 100% sure Randomize generate unique values.
Do you know method for unique values?
Are you running your app directly from the editor?It works with delphi 7
but it can't conncet in delphi 2013 XE4
this error appears:
"Host not found"
could you help me please?
thanks
Please, take me edited sswin32 file or say how edit sswin32 file(plaese edited code)? i try edit with your recomendation, but this is now work for me Thank you!I run it from the editor and also from windows exe file
Both of them face with the problem
I traced it and found the problem:
In delphi XE4 string type is default to WideString, but in delphi 7 it is AnsiString
I changed SetVarSin and GetAddr Functions Parameters (in sswin32 file) String--> AnsiString
and now it works
[dcc32 Fatal Error] MainForm.pas(7): F2613 Unit '..\Common\RouterOSAPI.pas' not found.
program APITest;
uses
Forms,
MainForm in 'MainForm.pas' {frmMain},
RouterOSAPI in 'RouterOSAPI.pas';
[dcc32 Fatal Error] RouterOSAPI.pas(67): F2613 Unit 'blcksock' not found.
[dcc32 Fatal Error] RouterOSAPI.pas(67): F2613 Unit 'synautil' not found.
[dcc32 Fatal Error] RouterOSAPI.pas(67): F2613 Unit 'synsock' not found.
[dcc32 Fatal Error] RouterOSAPI.pas(67): F2613 Unit 'synacode' not found.
those are from Ararat SynapseCode: Select all[dcc32 Fatal Error] RouterOSAPI.pas(67): F2613 Unit 'blcksock' not found. [dcc32 Fatal Error] RouterOSAPI.pas(67): F2613 Unit 'synautil' not found. [dcc32 Fatal Error] RouterOSAPI.pas(67): F2613 Unit 'synsock' not found. [dcc32 Fatal Error] RouterOSAPI.pas(67): F2613 Unit 'synacode' not found.
wrong topic. my client does not have any 'msend' command. also, plain password should not be sent over network (it's insecure!), you're doing something wrongHi all,
I have this error :
tr_mkrouter.msend /login
tr_mkrouter.msend /login
tr_mkrouter.msend =name=apiuser
tr_mkrouter.msend =password=2010 <-----{My clear password}
tr_mkrouter.msend =response=39582d42fb88ca42ae0958e46b24e318
tr_mkrouter.open opening router error = !trap=message=cannot log in
Delphi XE8.
Thanks for help
/tool user-manager user remove [find username=demo]
http://forum.mikrotik.com/viewtopic.php?t=26790How do I run this command with api?:Code: Select all/tool user-manager user remove [find username=demo]
http://wiki.mikrotik.com/wiki/Manual:API#QueriesThere is no explanations about signs (* = ? .)
as docmarius said, it should be something likeCould you please write a correct ROS.Query() for CLI command "/ip hotspot active print detail where user=username"?
I need to get mac-address of username from the result, i tried different variants, but unsuccessful ((
/ip/hotspot/active/print
=.proplist=mac-address
?user=username
procedure TForm1.btn1Click(Sender: TObject);
var
Res: TRosApiResult;
begin
Res := ROS.Query(['/ip/hotspot/active/print', '=.proplist=mac-address', '?user=fff'], True);
while not res.Eof do
begin
if Res.Trap then
ShowMessage('Trap: ' + ROS.LastError)
else
begin
label1.Caption := 'user: ' + Res['user'] + #13#10 + 'address: ' + Res['address'] + #13#10 +
'mac: ' + Res['mac-address'];
end;
res.Next;
end;
Res.Free;
end;
bwahaha, glad to hear that =)It's working!!!)))) I'm sorry, there was no active users))
Thank you very-very much!))
Checking project dependencies...
Compiling APITest.dproj (Debug, Win32)
dcc32 command line for "APITest.dpr"
c:\program files (x86)\embarcadero\studio\17.0\bin\dcc32.exe -$O- -$W+ --no-config -M -Q -TX.exe -AGenerics.Collections=System.Generics.Collections;
Generics.Defaults=System.Generics.Defaults;WinTypes=Winapi.Windows;WinProcs=Winapi.Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE -DDEBUG
-I"c:\program files (x86)\embarcadero\studio\17.0\lib\Win32\release";C:\Users\Daniel\Documents\Embarcadero\Studio\17.0\Imports;"c:\program files
(x86)\embarcadero\studio\17.0\Imports";C:\Users\Public\Documents\Embarcadero\Studio\17.0\Dcp;"c:\program files (x86)\embarcadero\studio\17.0\include";
"C:\Program Files (x86)\FastReports\LibD23" -LEC:\Users\Public\Documents\Embarcadero\Studio\17.0\Bpl
-LNC:\Users\Public\Documents\Embarcadero\Studio\17.0\Dcp -NSSystem.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;Vcl;Vcl.Imaging;Vcl.Touch;
Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi; -O"c:\program files (x86)\embarcadero\studio\17.0\lib\Win32\release";
C:\Users\Daniel\Documents\Embarcadero\Studio\17.0\Imports;"c:\program files (x86)\embarcadero\studio\17.0\Imports";
C:\Users\Public\Documents\Embarcadero\Studio\17.0\Dcp;"c:\program files (x86)\embarcadero\studio\17.0\include";"C:\Program Files
(x86)\FastReports\LibD23" -R"c:\program files (x86)\embarcadero\studio\17.0\lib\Win32\release";
C:\Users\Daniel\Documents\Embarcadero\Studio\17.0\Imports;"c:\program files (x86)\embarcadero\studio\17.0\Imports";
C:\Users\Public\Documents\Embarcadero\Studio\17.0\Dcp;"c:\program files (x86)\embarcadero\studio\17.0\include";"C:\Program Files
(x86)\FastReports\LibD23" -U"c:\program files (x86)\embarcadero\studio\17.0\lib\Win32\release";
C:\Users\Daniel\Documents\Embarcadero\Studio\17.0\Imports;"c:\program files (x86)\embarcadero\studio\17.0\Imports";
C:\Users\Public\Documents\Embarcadero\Studio\17.0\Dcp;"c:\program files (x86)\embarcadero\studio\17.0\include";"C:\Program Files
(x86)\FastReports\LibD23" -K00400000 -NBC:\Users\Public\Documents\Embarcadero\Studio\17.0\Dcp
-NHC:\Users\Public\Documents\Embarcadero\Studio\17.0\hpp\Win32 APITest.dpr
[dcc32 Warning] synautil.pas(529): W1057 Implicit string cast from 'AnsiString' to 'string'
[dcc32 Warning] synautil.pas(529): W1057 Implicit string cast from 'AnsiString' to 'string'
[dcc32 Warning] synautil.pas(537): W1057 Implicit string cast from 'AnsiString' to 'string'
[dcc32 Warning] synautil.pas(537): W1058 Implicit string cast with potential data loss from 'string' to 'AnsiString'
[dcc32 Warning] synautil.pas(539): W1057 Implicit string cast from 'AnsiString' to 'string'
[dcc32 Error] synautil.pas(555): E2003 Undeclared identifier: 'TimeSeparator'
[dcc32 Warning] synautil.pas(665): W1058 Implicit string cast with potential data loss from 'string' to 'AnsiString'
[dcc32 Warning] synautil.pas(1405): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit.
[dcc32 Warning] synautil.pas(1666): W1057 Implicit string cast from 'AnsiString' to 'string'
[dcc32 Warning] synautil.pas(1690): W1044 Suspicious typecast of AnsiString to PWideChar
[dcc32 Warning] synautil.pas(1707): W1044 Suspicious typecast of AnsiString to PWideChar
[dcc32 Warning] synautil.pas(1733): W1044 Suspicious typecast of AnsiString to PWideChar
[dcc32 Warning] synautil.pas(1742): W1044 Suspicious typecast of AnsiString to PWideChar
[dcc32 Warning] synautil.pas(1742): W1044 Suspicious typecast of AnsiString to PWideChar
[dcc32 Warning] synautil.pas(1742): W1044 Suspicious typecast of AnsiString to PWideChar
[dcc32 Warning] synautil.pas(1743): W1044 Suspicious typecast of AnsiString to PWideChar
[dcc32 Warning] synautil.pas(1744): W1044 Suspicious typecast of AnsiString to PWideChar
[dcc32 Warning] synautil.pas(1744): W1044 Suspicious typecast of AnsiString to PWideChar
[dcc32 Error] synautil.pas(1766): E2003 Undeclared identifier: 'ShortMonthNames'
[dcc32 Fatal Error] blcksock.pas(92): F2063 Could not compile used unit 'synautil.pas'
Failed
Elapsed time: 00:00:01.0
/tool/torch
=interface=ether1
/tool/torch
=interface=ether1
=src-address=0.0.0.0/0
/ip/hotspot/profile/getall
to remove property value in Terminal you use 'unset' command, not 'set'. so use it in API:remove local-address is remote-address ?
/ppp/secret/unset
=.id=*654
=value-name=local-address
/ppp/secret/unset
=.id=*654
=value-name=remote-address
I'm too late?The selected attachment does not exist anymore.
Nice, as it should have been. Forum is not a great file storage solution.Uploaded files to GitHub: https://github.com/Chupaka/Delphi-RouterOS-API/releases
Thank you, Mr.Chupaka!Uploaded files to GitHub: https://github.com/Chupaka/Delphi-RouterOS-API/releases
And what does it test?Mikrotik API Tester
OK you are right. GUI Language English.And what does it test?Mikrotik API Tester
Comments are in Turkish, so they are a bit hard to understand...
Hi. That's weird. Any logins should be logged anyway (unless Logging is disabled for this topic).Chupaka hello man! how are you??? How can I connect my RB and keep connected as Mikro WInbox and own App Mikrotik also not showing activity logging on the RB???? I downlado both and either not show when connect and query the RB!!! Thanks
Wrong topic or just spam bot?I've got a problem here with an Android 8.1 device - it disconnects every 2-3 minutes with the same messages.
If you're refering to the APITest-1.3.exe executable, when I run it and I check the TLS checkbox I got this error when trying to connect:Did you try API Test program? It works for me with SSL.
Chupaka, after you said, I just realised it is true, it always do a log, the problem coz I did a code that login logout... so it keeps shwoing then!!! my mistake! by the way, do you know how to create a RADIUS with Delphi, I have seen some videos, but OMG, it is so complicated, coz need to run linux, installl mysql and etc etc... any easier path to create an app with radius! thanks!!!Hi. That's weird. Any logins should be logged anyway (unless Logging is disabled for this topic).Chupaka hello man! how are you??? How can I connect my RB and keep connected as Mikro WInbox and own App Mikrotik also not showing activity logging on the RB???? I downlado both and either not show when connect and query the RB!!! Thanks
Wrong topic or just spam bot?I've got a problem here with an Android 8.1 device - it disconnects every 2-3 minutes with the same messages.
Probably you need libeay32.dll and ssleay32.dllIf you're refering to the APITest-1.3.exe executable, when I run it and I check the TLS checkbox I got this error when trying to connect:
---------------------------
RouterOS API Demo
---------------------------
Connection error: No SSL/TLS support compiled
---------------------------
I wrote my own implementation of RADIUS server many years ago... And yes, it was for MikroTik DHCP requests xDby the way, do you know how to create a RADIUS with Delphi, I have seen some videos, but OMG, it is so complicated, coz need to run linux, installl mysql and etc etc... any easier path to create an app with radius! thanks!!!
Undertood but didn't figure out how LOL did it work for you???? any simple example xDI wrote my own implementation of RADIUS server many years ago... And yes, it was for MikroTik DHCP requests xDby the way, do you know how to create a RADIUS with Delphi, I have seen some videos, but OMG, it is so complicated, coz need to run linux, installl mysql and etc etc... any easier path to create an app with radius! thanks!!!
Perfect. That worked for the API Test application.Probably you need libeay32.dll and ssleay32.dllConnection error: No SSL/TLS support compiled
I don't even remember the details It was a bit monolithic project, I'm not even sure if I can quickly extract RADIUS part from itUndertood but didn't figure out how LOL did it work for you???? any simple example xD
hahahahaha LOL.... I will compile and send it to tge group to together find the error!!! =)"Something, Inc." is nice but not very clear error
Correct form of this command is "/system script run scriptname", so in API it would bein winbox's terminal this command : /system script run 0 works fine.
what is equivalent command in RouterOS API?
already try /system/script/run 0 in APITest.exe, click Exec button and i got ERROR: no such command.
tested on SXTsq 5ac version 6.42.7 (stable).
/system/script/run
=.id=scriptname
[admin@MikroTik] /system script> pr
Flags: I - invalid
0 name="LogMe" owner="admin" policy=read,write,policy,test,sensitive last-started=jul/16/2019 09:23:43 run-count=5
source=log info "from script";
1 name="KonekWms" owner="admin" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon run-count=0
source=
:if ([/ping address=8.8.8.8 count=2] = 0) do={
/ip dns cache flush
/ip dhcp-client release [find interface=wlan1]
log warning "NEW DHCP CLIENT"
delay 5
log error "WMS IS DOWN, trying to reconnect"
:local mac [/interface wireless get [find name=wlan1] mac-address];
:local ip [/ip address get [/ip address find interface="wlan1"] address];
:local ip [:pick $ip 0 [:find $ip "/"]];
/tool fetch http-method=post http-data="password=tolaklemot" url=("https://welcome2.wifi.id/wms/?gw_id=CEPUKOM&c
lient_mac=$mac")
keep-result=no;
} else {
log warning "WMS IS UP"
}
/system/script/run
=.id="Logme"
/system/script/run
=.id=Logme
/system/script/run
=.id=*1
/system script
add dont-require-permissions=no name=LogMe owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="log info \"from script\";"
/system/script/run
=.id=LogMe
Connected!
Version: 6.45.1 (stable)
Done================
Not now, because it has already been done more than a year ago. Please first check then ask silly questions.Master Chupaka, do you intent send an update of RouterOSAPI.pas with the new way to login via delphi?
https://wiki.mikrotik.com/wiki/Manual:API#Initial_login
Thanks
v1.3: Added support for RouterOS 6.43+ API login method
Not now, because it has already been done more than a year ago. Please first check then ask silly questions.Master Chupaka, do you intent send an update of RouterOSAPI.pas with the new way to login via delphi?
https://wiki.mikrotik.com/wiki/Manual:API#Initial_login
Thanks
v1.3: Added support for RouterOS 6.43+ API login method
Looks like you need to enable or allow access to API port on your router.My English is bad. Master Chupaka I use delphi tokyo and when connecting get or error: socket recv timeout in sockRecvbufferStr. Is there anything I can do to use on Tokyo?
procedure Tmainform.JvImage1Click(Sender: TObject);
var
Res: TRosApiResult;
f: Boolean;
begin
if chkTLS.Checked then
f := ROS.SSLConnect(edremotIP.Text, edUsername.Text, edPassword.Text)
else
f := ROS.Connect(edremotIP.Text, edUsername.Text, edPassword.Text);
if f then
begin
mem.Lines.Add('Connected!');
Res := ROS.Query(['/system/resource/print'], True);
if Res.Trap then
mem.Lines.Add('Trap: ' + ROS.LastError)
else
begin
mem.Lines.Add('Version: ' + Res['version']);
end;
Res.Free;
page1.enabled:=true;
end..else
begin
ShowMessage('Connection error: ' + ROS.LastError);
Exit;
end;
end;
I believe you just need to update the client to v1.3:
i have this proc it s good with version 6.40 but with version 6.5 i have this error
connection error:invalide user name or password (6)
so can you write for me procedure delphi api with new version 6.45 thank....
v1.3: Added support for RouterOS 6.43+ API login method
Leaving it here for historical reasons: "don't connect with API client to WinBox port, those are completely different services"The error takes time, it is not immediate
/ip firewall address-list add address=45.199.34.5 list=clientes
/ip/firewall/address-list/add
=address=45.199.34.5
=list=clientes
First, find the .id of necessary item:/ip firewall address-list remove [find where address=45.199.34.5 && list=clientes]
/ip/firewall/address-list/print
=.proplist=.id
?address=45.199.34.5
?list=clientes
/ip/firewall/address-list/remove
=.id=ID_FROM_PREVIOUS_STEP
Hello./ip firewall address-list add address=45.199.34.5 list=clientesCode: Select all/ip/firewall/address-list/add =address=45.199.34.5 =list=clientes
First, find the .id of necessary item:/ip firewall address-list remove [find where address=45.199.34.5 && list=clientes]Then remove it:Code: Select all/ip/firewall/address-list/print =.proplist=.id ?address=45.199.34.5 ?list=clientes
Code: Select all/ip/firewall/address-list/remove =.id=ID_FROM_PREVIOUS_STEP
Perfect.. I will install delphi 11, thanksHave you tried?
Works for me.