I am trying to extract from a list called Blacklist an IP address and convert it to cidr format.
Ex. 194.243.25.13 -> 194.243.25.0/24
Code: Select all
:foreach id in=[ip firewall address-list find list="Blacklist" address~"^[0-9\\.]*\$"] do={
local ipAddr [/ip firewall address-list get $id address];do {
/ip firewall address-list add address=($ipAddr."/24") list=BlacklistIPSEC comment=IPSec timeout=7d
:local filenameIP "BlacklistIPSEC.txt"
/file
:if ([:len [find where name="flash" and type="disk"]] = 1) do={:set filenameIP "flash/$filenameIP"}
:if ([:len [find where name=$filenameIP]] = 0) do={print file="$filenameIP"; :delay 5s; set $filenameIP contents=""}
:delay 5s
:local filecontent [get $filenameIP contents]
:local newfilecontent "($ipAddr.$cidr)\r\n$filecontent"
set $filenameIP contents=$newfilecontent
} on-error={
# log info message="duplicate address found"}
}
}
But then I try to save those new IP addresses in BlacklistIPSEC also line by line in a file called BlacklistIPSEC.txt, but I didn't succeed.
Any help please?