Very nice job. Great script and ideas. I know the point of your text was to illustrate the script and the automation behind it, but since you used a real life situation, I'd like to offer my two cents on that.
Instead of adding those IP addresses to an iptables script like that, you could try to take advantage of cloudflare's free plan to defend your vps. I'm not their employee, just a happy user. I manage small cloud servers as a side job and their firewall allows you to add a small captcha to validate a connection instead of simply blocking it. And you can create rules for specific countries. If you block an IP, there's no way for it to reach your website, even if it's a legitimate connection. A captcha is boring for the users, but it costs them only one click ;)
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.