Created
February 21, 2018 19:38
-
-
Save anonymous/956252984d1d0df2ca5a2efc4e934fdf to your computer and use it in GitHub Desktop.
Mikrotik script to sync address list with uablacklist.net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:local apiPath "https://uablacklist.net/subnets_mikrotik.txt" | |
:local tempFile "uablacklist.txt" | |
:local listName "uablacklist" | |
/log info "fetching UA blacklist registry ($apiPath)..." | |
:put "fetching UA blacklist registry ($apiPath)..." | |
/tool fetch url=$apiPath dst-path=$tempFile | |
/log info "removing existing $listName..." | |
:put "removing existing $listName..." | |
/ip firewall address-list remove [/ip firewall address-list find list=$listName] | |
:local content [/file get [/file find name=$tempFile] contents] | |
:local contentLen [:len $content] | |
:local lineEnd 0 | |
:local line "" | |
:local lastEnd 0 | |
:local company "" | |
:do { | |
:set lineEnd [:find $content "\n" $lastEnd ] | |
:set line [:pick $content $lastEnd $lineEnd] | |
:set lastEnd ($lineEnd+1) | |
:local entry [:pick $line 0 ($lineEnd-1)] | |
:if ([:pick $line 0 1] != "#") do={ | |
:if ([:len $entry ] > 0) do={ | |
/log info "add $entry subnet of $company to list $listName..."; | |
:put "add $entry subnet of $company to list $listName..."; | |
/ip firewall address-list add list=$listName address=$entry comment=$company | |
} | |
} else={ | |
:set company [:pick $line 2 ($lineEnd) ] | |
} | |
} while ($lastEnd < $contentLen) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment