Community discussions

MikroTik App
 
HaPe
Member Candidate
Member Candidate
Topic Author
Posts: 239
Joined: Fri Feb 10, 2012 10:24 pm
Location: Poland

Loop for remove ip from address list

Thu Sep 26, 2013 8:31 pm

Hi. I need script to remove ip's from address list if IP isn't assigned to any active ppp session. How to write this loop?
I tried that, but it doesn't work.

ros code

:foreach ip in=[/ip firewall address-list find] do {
    :foreach ip2 in=[/ppp active find] do {
        :if ($ip != ip2) do={/ip firewall address-list [:find address=$ip2}
    }
}
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Loop for remove ip from address list

Thu Sep 26, 2013 11:03 pm

Try this:

ros code

/ip firewall address-list
:foreach ip in=[find] do={
  :if ([:len [/ppp active find address=[get $ip address]]] = 0) do={
    remove [find address=[get $ip address]]
  }
}
 
HaPe
Member Candidate
Member Candidate
Topic Author
Posts: 239
Joined: Fri Feb 10, 2012 10:24 pm
Location: Poland

Re: Loop for remove ip from address list

Sat Sep 28, 2013 3:06 pm

Thank you. But id doesn't work.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Loop for remove ip from address list

Mon Sep 30, 2013 2:21 am

Try this instead. Problem with the previous code I explained here in your other post.

ros code

/ip firewall address-list
:foreach ip in=[find] do={
  :local add [get $ip address]
  :if ([:len [/ppp active find address=$add]] = 0) do={
    remove $ip
  }
}
HTH
 
HaPe
Member Candidate
Member Candidate
Topic Author
Posts: 239
Joined: Fri Feb 10, 2012 10:24 pm
Location: Poland

Re: Loop for remove ip from address list

Mon Sep 30, 2013 7:52 am

Thank you.

Who is online

Users browsing this forum: No registered users and 29 guests