Block naughty IP's with UFW
Let that little firewall work.
This handy script can be run from cron every 6.5 hours to automatically update your UFW firewall with an updated list of bad IP addresses. UFW, or Uncomplicated Firewall, is a small, straightforward Linux firewall that does the job. It’s simple to use, effective, and highly recommended.
You can run it on your server, PC, or laptop. I have UFW running in the background on every laptop I use. It's important to remember that security is a matter of layers, rather than relying on a single tool.
The code below is a modified version of the original script, which has not been updated since its initial release in 2018. The original contained some typographical errors that caused issues. For example, the denyHost()
function confirmed every IP address added to the firewall, which could be annoying and the getLists()
function referenced the wrong variable, while the Python call was outdated.
This revised version works perfectly; it has been running on my laptop since this morning without any problems.