Skip to content

Instantly share code, notes, and snippets.

@ccrsxx
Last active June 11, 2024 01:32
Show Gist options
  • Save ccrsxx/6684be44f8a975af4b48067e4a5d4966 to your computer and use it in GitHub Desktop.
Save ccrsxx/6684be44f8a975af4b48067e4a5d4966 to your computer and use it in GitHub Desktop.
# Set the address list name
:local blackListName "z_dns_ips_blacklist"
# Set the whitelisted IPs
# GitHub, Vercel, Tailscale in ascending order
:local whiteListIPs [:toarray \
" \
185.199.108.153, \
185.199.109.153, \
185.199.110.153, \
185.199.111.153, \
76.76.21.9, \
76.76.21.21, \
" \
]
# Download the DNS IP blacklist file
/tool fetch url="https://raw.githubusercontent.com/jpgpi250/piholemanual/master/DOHipv4.txt" \
mode=https dst-path=$blackListName
:log info "FINISHED FETCHING FILE"
# Adding a delay
# ! Adding a delay to ensure the file can be read properly
# ! This only needed on the latest RouterOS version v7.15.*
# ! Previous versions works fine v7.14.3 or below without this workaround
# :delay 1s
# Read the blacklist file
# ! Below line can throw an error sometimes after we download the file on the latest RouterOS version v7.15.*
:local blacklistFile [/file get $blackListName contents]
:log info "FINISHED READING FILE"
# :local blacklistFileLength [:len $blacklistFile]
# :log info "FINISHED READING FILE LINES"
# # Remove the old address list
# /ip firewall address-list remove [find list=$blackListName]
# :log info "FINISHED REMOVING"
# # Variable for parsing the file
# :local line ""
# :local lineEnd 0
# :local lastEnd 0
# :log info "FINISHED REMOVING 2"
# :while ($lineEnd < $blacklistFileLength) do={
# # Depending on file type (linux/windows), "\n" might need to be "\r\n"
# :set lineEnd [:find $blacklistFile "\n" $lastEnd]
# # If there are no more line breaks, set this to be the last one
# :if ([:len $lineEnd] = 0) do={
# :set lineEnd $blacklistFileLength
# }
# # Get the current line based on the last line break and next one
# :set line [:pick $blacklistFile $lastEnd $lineEnd]
# # Depending on "\n" or "\r\n", this will be 1 or 2 accordingly
# :set lastEnd ($lineEnd + 1)
# # Don't process blank lines and empty lines
# :if ($line != "\r" && [:typeof $line] != "nil") do={
# :local whiteListedIp [:find $whiteListIPs $line]
# if ([:typeof $whiteListedIp] = "nil") do={
# /ip firewall address-list add address=$line list=$blackListName comment="Blacklisted DNS IP"
# }
# if ([:typeof $whiteListedIp] = "num") do={
# /ip firewall address-list add address=$line list=$blackListName disabled=yes comment="Whitelisted DNS IP"
# }
# }
# }
# Clean up
/file remove $blackListName
:log info "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment