Skip to content

Instantly share code, notes, and snippets.

@uablacklist
Last active July 9, 2024 22:11
Show Gist options
  • Save uablacklist/b0e73deb75f2a1c43f035c59e5401e8c to your computer and use it in GitHub Desktop.
Save uablacklist/b0e73deb75f2a1c43f035c59e5401e8c to your computer and use it in GitHub Desktop.
Добавляет IP подсети, заблокированные украинским правительством, из https://uablacklist.net в список адресов вашего Mikrotik
:local apiPrefix "https://uablacklist.net/subnets_mikrotik_"
: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)
@A-I-Demidov
Copy link

Что происходит с uablacklist.net не работает сайт, соответственно и скрипт...

Сайт работает.

Возможно, у вашего провайдера он заблокирован, проверьте как разолвится его DNS имя и попробуйте перенаправить роутинг к нему сразу в VPN.

Но вообще рекомендую не список, а перейти на BGP https://antifilter.network/bgp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment