Datasheet

Manual:API Python3
81
if __name__ == '__main__':
main()
file
|api client in python3
[1]
References
[1] http:/ / wiki. mikrotik. com/ images/ 6/ 6b/ Api. txt
API multiplatform from townet
MKAPI: LIBRARY TO CONTROL MIKROTIK BOARDS
This article refers to the library developed by townet to control a mikrotik boad using the api, and to the example
applications developed using the same library. The library is written in C++, and works under Linux and under
Windows.
You can download the lybrary and the SKD, that contains also the manual at the address:
www.wispmax.com/media/CPE_SDK.zip
The port used for the mikrotik API is the 8723. On the CPE machine te API needs to be enabled.
1.1. define API_PORT 8728
This are some functions usable to read the parameters received in a message froma mikrotik board.
AnsiString parse_par(AnsiString stream, char* par, char* dest); AnsiString parse_line(char* reply);
class mikrotikBoard { public:
The one under is the login function, to start the connection. To do the login you needs to give the IP address, the
username and the password. You will receive back an empty string it the login is correct, or a string that describe the
error that caused the wrong login.
AnsiString login(AnsiString remote, AnsiString user, AnsiString pass);
The commandfunction is used to handle a transactional command. This function needs to have the command as a
parameter, and gives back the reply received from the mikrotik board. If a trapis received, this mean that an error
occoured, and a messageBox is shown to the user.
AnsiString command(AnsiString text);
The xcommandfunction allows, like the one before, to execute a transactional command, with the difference that
in case of a trap no messagebox giving back the error is generated. The task of handling the error remain to te
applications programmer. The xcommandway is more flexible, and useful in case of a command that, may be, was
allread given to the board.
AnsiString xcommand(AnsiString text);
To handle interactive commands, like for example scan:
void start_icommand(AnsiString cmd); //Starts an interactive command
AnsiString icommand(); //Reads part of the reply to the interactive command
AnsiString end_icommand(); //This is called to close the icommand