Datasheet
API multiplatform from townet
83
{ AnsiString line = parse_line(&c);
//Here the variable line contains only a line from the reply.
char adr[30];
char interf[20];
parse_par(line, "address=", adr);
parse_par(line, "interface=", interf);
printf("Interface %s \taddress %s\n", interf, adr);
};
};
More easily the function parse_par can be used to read the first occourrence of a parameter and to cut the original
string, so you can gradually read all the results, in this way:
mikrotikboard mk;
AnsiString res=mk.login("192.168.1.1", "admin", "print");
if (res="")
{ AnsiString indirizzi =mk.command("/ip/address/print");
//This copy the string on a buffer of chars
char c[10000]; strcpy(c, indirizzi.c_str());
while (indirizzi !="")
{ char adr[30];
char interf[20];
line = parse_par(line, "address=", adr);
line=parse_par(line, "interface=", interf);
printf("Interfaccia %s \tindirizzo %s\n", interf, adr);
};
};
Reading the reply you have to be careful for a thing: if the “interface” information is given in the reply before the
“address”, the results can be printed in a wrong position.
The MkApi library define many other functions, but this are aminly low-level ones, and are used to build the ones
we descrived before. So we decided not to give documentation about it. If you select to use the “DLL” version of the
MkApi library you can write a similar program using any language, like for example basic or c#, without an
excessive loose of speed. The same library work also under linux, and can be linked as an object file os as a .so
dynamic linked library.
COMMAND LINE UTILITY TO HANDLE MIKROTIK BOARDS
Mik utility is a ms-dos and linux command line application that allows to execute commands on a mikrotik board in
a “batch” way. It’s possible to use it from the command line or using scripts written in many languages. Pratically all
the programming languages have a shell construct (in basic for example the construct is “system”). SO it’ s possible
to execute an external application and then resume the normal execution of a program. So this utility can be used to
have a program written in any language that talks with routeros.
Launching the utility mik you will ever have two replies: a first line containing a number followed from the text Err
or Ok , and he following lines containing a detailed reply.
If the details of the reply are not importants for the calling application, for example if mik is givin back his internal
short manual, this details are not returned on the standard output but on the standard error.
./mik -1 Err Parametri errati










