User Tools

Site Tools


networking:router:mikrotik_manual_blacklist

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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://forum.mikrotik.com/viewtopic.php?t=105444+FIXME **New**: https://forum.mikrotik.com/viewtopic.php?t=105444
  
 :!: This assumes you have a address list named ''blacklist'' that is being blocked. :!: This assumes you have a address list named ''blacklist'' that is being blocked.
Line 60: Line 60:
 </file> </file>
  
 +====== 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 ''ipaddress.txt'' file.
 +
 +:!: Make sure the ''ipaddress.txt'' file is less than 4K in size.
 +
 +<file>
 +/system script add dont-require-permissions=no name=add-ip-addresses-to-blacklist owner=\
 +    admin policy=\
 +    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="#\
 +    # 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 \"\";\r\
 +    \n:put \"This script requires the address text file to have UNIX line endings.\";\r\
 +    \n\
 +    \n:put \"\";\r\
 +    \n:put \"Hard coded source is file ipaddress.txt file.\";\r\
 +    \n\
 +    \n:put \"Hard coded destination is the blacklist address-list.\";\r\
 +    \n\
 +    \n:put \"Comment for imported entries is hard coded in the script.\";\r\
 +    \n\
 +    \n:put \"The ipaddress.txt file must be smaller than 4KB.\";\r\
 +    \n:put \"\";\r\
 +    \n##:put \"Removing all old address-list entries...\";\r\
 +    \n##/ip firewall address-list remove [/ip firewall address-list find list=blacklist];\r\
 +    \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 \"\";\r\
 +    \n:global lastEnd 0;\r\
 +    \n:do {\r\
 +    \n      :set lineEnd [:find \$content \"\\n\" \$lastEnd ] ;\r\
 +    \n      :set line [:pick \$content \$lastEnd \$lineEnd] ;\r\
 +    \n      :set lastEnd ( \$lineEnd + 1 ) ;\r\
 +    \n      #If the line doesn't start with a hash then process and add to the list\r\
 +    \n      :if ( [:pick \$line 0 1] != \"#\" ) do={\r\
 +    \n      :local entry [:pick \$line 0 \$lineEnd ]\r\
 +    \n      :if ( [:len \$entry ] > 0 ) do={\r\
 +    \n         :put \"Removing \$entry from blacklist, if it exists\";\r\
 +    \n         /ip firewall address-list remove [find list=\"blacklist\" address=\$entry];\r\
 +    \n         :put \"Address being added is \$entry\";\r\
 +    \n         /ip firewall address-list add list=blacklist address=\$entry comment=\"Spammer\";\r\
 +    \n         }\r\
 +    \n      }\r\
 +    \n    } while (\$lineEnd < \$contentLen)\r\
 +    \n}"
 +
 +</file>
networking/router/mikrotik_manual_blacklist.1708811192.txt.gz · Last modified: 2024/02/24 14:46 by gcooper