One of the function of the program I`m doing is to add an specific rule X after another specific rule Y. That is easy when all the firewall rules are static and Y is always the same number. For example the rule Y is always in number 37 so I simply add:
Code: Select all
mikrotik.Send("/ip/firewall/filter/add");
mikrotik.Send("=place-before=38");....
This is what I've tried without success:
Code: Select all
mikrotik.Send("/ip/firewall/filter/print");
mikrotik.Send("?dst-address=x.x.x.x/x");
mikrotik.Send("=.proplist=.id=" + id, true);
mikrotik.Send("/ip/firewall/filter/add");
mikrotik.Send("=place-before=" + id);
Code: Select all
mikrotik.Send("/ip/firewall/filter/print");
mikrotik.Send("?dst-address=x.x.x.x/x", true);
foreach (var item in mikrotik.Read())
{
id = item;
}
mikrotik.Send("=place-before=" + id);
Wiki doesn't help much:
Code: Select all
place-before - places a new item before an existing item with specified position. Thus, you do not need to use the move command after adding an item to the list
Thanks
EDIT: I 've figured it out, I leave this here so it maybe can help someone like me. This is the solution I've found, I had to split and get the id from the string:
Code: Select all
mikrotik.Send("/ip/firewall/filter/print");
mikrotik.Send("?dst-address=x.x.x.x/x");
mikrotik.Send("=.proplist=.id",true);
foreach (var item in mikrotik.Read())
{
id += item;
}
//Id = !re=.id=*25!done
string sub = id.Substring(id.IndexOf("*"), id.LastIndexOf("!") - id.IndexOf("*"));
//sub = *25
mikrotik.Send("/ip/firewall/filter/add");
mikrotik.Send("=place-before=" + sub);