This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
networking:router:mikrotik_manual_blacklist [2024/02/24 14:46] gcooper |
networking:router:mikrotik_manual_blacklist [2025/02/25 16:10] (current) gcooper |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Manually Add and Remove IP Addresses to a Mikrotik Blacklist ====== | ====== Manually Add and Remove IP Addresses to a Mikrotik Blacklist ====== | ||
- | **New**: https:// | + | FIXME **New**: https:// |
:!: This assumes you have a address list named '' | :!: This assumes you have a address list named '' | ||
Line 60: | Line 60: | ||
</ | </ | ||
+ | ====== Script ====== | ||
+ | |||
+ | FIXME Super slow and may not be 100% correct for ROS v7. | ||
+ | |||
+ | :!: You should first run this script at the ROS command line to look for errors. | ||
+ | |||
+ | :!: Make sure UNIX line endings are used in the '' | ||
+ | |||
+ | :!: Make sure the '' | ||
+ | |||
+ | < | ||
+ | /system script add dont-require-permissions=no name=add-ip-addresses-to-blacklist owner=\ | ||
+ | admin policy=\ | ||
+ | ftp, | ||
+ | # Generic IP address list input\r\ | ||
+ | \n## Based on a script written by Sam Norris, ChangeIP.com 2008\r\ | ||
+ | \n## Edited by Andrew Cox, AccessPlus.com.au 2008\r\ | ||
+ | \n##\r\ | ||
+ | \n:put \" | ||
+ | \n:put \"This script requires the address text file to have UNIX line endings.\"; | ||
+ | \n\ | ||
+ | \n:put \" | ||
+ | \n:put \"Hard coded source is file ipaddress.txt file.\"; | ||
+ | \n\ | ||
+ | \n:put \"Hard coded destination is the blacklist address-list.\"; | ||
+ | \n\ | ||
+ | \n:put \" | ||
+ | \n\ | ||
+ | \n:put \"The ipaddress.txt file must be smaller than 4KB.\"; | ||
+ | \n:put \" | ||
+ | \n##:put \" | ||
+ | \n##/ip firewall address-list remove [/ip firewall address-list find list=blacklist]; | ||
+ | \n:global content [/file get [/file find name=ipaddress.txt] contents] ;\r\ | ||
+ | \n:global contentLen [ :len \$content ] ;\r\ | ||
+ | \n:global lineEnd 0;\r\ | ||
+ | \n:global line \" | ||
+ | \n:global lastEnd 0;\r\ | ||
+ | \n:do {\r\ | ||
+ | \n :set lineEnd [:find \$content \" | ||
+ | \n :set line [:pick \$content \$lastEnd \$lineEnd] ;\r\ | ||
+ | \n :set lastEnd ( \$lineEnd + 1 ) ;\r\ | ||
+ | \n #If the line doesn' | ||
+ | \n :if ( [:pick \$line 0 1] != \"# | ||
+ | \n :local entry [:pick \$line 0 \$lineEnd ]\r\ | ||
+ | \n :if ( [:len \$entry ] > 0 ) do={\r\ | ||
+ | \n :put \" | ||
+ | \n /ip firewall address-list remove [find list=\" | ||
+ | \n :put \" | ||
+ | \n /ip firewall address-list add list=blacklist address=\$entry comment=\" | ||
+ | \n }\r\ | ||
+ | \n }\r\ | ||
+ | \n } while (\$lineEnd < \$contentLen)\r\ | ||
+ | \n}" | ||
+ | |||
+ | </ |