Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Добавляет IP подсети, заблокированные украинским правительством, из в список адресов вашего Mikrotik
:local apiPrefix ""
:local tempFile "uablacklist.txt"
:local listName "uablacklist"
/log info "removing existing '$listName'..."
:put "removing existing '$listName'..."
/ip firewall address-list remove [/ip firewall address-list find list=$listName]
# mikrotik can't load >4KB file inside a variable, so backend contains file pieces which we download and parse one by one
:local i 0
:local isEnd false
:do {
:local apiPath "$apiPrefix$i.txt"
/log info "fetching UA blacklist registry piece ($apiPath)..."
:put "fetching UA blacklist registry piece ($apiPath)..."
:local contentLen 0
:local content ""
:do {
/tool fetch url=$apiPath dst-path=$tempFile
:set content [/file get [/file find name=$tempFile] contents]
:set contentLen [:len $content]
} on-error={
/log info "no more pieces";
:put "no more pieces"
:set isEnd true
:local lineEnd 0
:local line ""
:local lastEnd 0
:local company ""
:while ($lastEnd < $contentLen) 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'...";
:do {
/ip firewall address-list add list=$listName address=$entry comment=$company
} on-error={
/log info "failed to add '$entry' subnet of '$company' to list '$listName', probably, it's duplication error.";
:put "failed to add '$entry' subnet of '$company' to list '$listName', probably, it's duplication error."
} else={
:set company [:pick $line 2 ($lineEnd) ]
:set i (i+1)
} while (!$isEnd)

This comment has been minimized.

Copy link
Owner Author

@uablacklist uablacklist commented Jul 21, 2019

Как использовать сгенерированные списки:
Чтобы иметь постоянно актуальный список, добавьте запуск скрипта в System - Scheduler следующей командой:
/system scheduler add name=sync_uablacklist interval=12:00:00 on-event="/system script run sync_uablacklist"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.