Community discussions

 
waffen
just joined
Topic Author
Posts: 1
Joined: Sun Dec 09, 2018 10:27 pm

How can i move a firewall filtre rule row id to another row id with c# api

Sun Dec 09, 2018 10:32 pm

I'm processing trying on c # with api codes in the bottom lines but it doesn't work.
I am using a MK api class

mikrotik.Send("/ip/firewall/filter/move");
mikrotik.Send("=[find");
mikrotik.Send("=comment=KURAL_1]");
mikrotik.Send("=35", true);
 
nescafe2002
Long time Member
Long time Member
Posts: 622
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: How can i move a firewall filtre rule row id to another row id with c# api

Mon Dec 10, 2018 12:01 pm

You can only 'find' in print command using query words.

https://wiki.mikrotik.com/wiki/Manual:API#Queries

Alternative is to fetch (print) with criteria and move using acquired ID.

Working (tested) example:

mikrotik.Send("/ip/firewall/filter/print");
mikrotik.Send("=.proplist=.id");
mikrotik.Send("?comment=KURAL_1", true);

string id = null;

foreach (var h in mikrotik.Read())
{
  var startIndex = h.IndexOf(".id=") + 4;
  if (startIndex >= 4)
  {
    id = h.Substring(startIndex);
  }
}

if (!string.IsNullOrEmpty(id))
{
  mikrotik.Send("/ip/firewall/filter/move");
  mikrotik.Send("=.id=" + id);
  mikrotik.Send("=destination=35", true);
}

If multiple lines match, the last one will be moved. Do not add a break; to interrupt the loop in this case. If it is undesirable, create a list of ids and process the first/last/middle accordingly.

Who is online

Users browsing this forum: No registered users and 14 guests