I took a look at my dashboard the other day and was horrified to see that I had more than 10,000 spam comments. That’s just plain ridiculous! So, while Akismet is stopping the spam from appearing on my site, I nonetheless wanted to block those IP addresses from even accessing my site, to stop my database from getting overloaded with spam.
It wasn’t as easy as I would have thought to find an answer to this, but I found a nice simple little plugin that did exactly what I wanted. I wanted to find recurring spammers and block them. So I needed a way to sort through all of my spam comments and find the prolific offending IP addresses, so that I could block them.
I found solace in the WP-Blacklister plugin. It’s very small and lightweight and does three simple tasks. It sorts through your spam comments and lists them by IP addresses, email addresses and URLs. The one I was interested in was the IP addresses.
Once you install it and go to the settings page, you can sort the columns by the number of spam comments left by each IP address / email address / URL. Once you’ve sorted them, you can then copy the IP addresses and paste them in your htaccess file to deny them access to your site. In my case, I chose to block anyone with more than 10 spam comments, so I sorted the IP list, copied my selection and pasted them in to htaccess to block them.
So that you know how to do it, this is the syntax that you need to use to block users from accessing your site by IP address. You can simply repeat this line as many times as you need for as many IP addresses as you have and paste it into your .htaccess file in the root of your website:
deny from 22.214.171.124 deny from 126.96.36.199 deny from 188.8.131.52 deny from 184.108.40.206 deny from 220.127.116.11 deny from 18.104.22.168 deny from 22.214.171.124
And it’s that easy. I’m going to keep it installed and keep checking back occasionally to identify any new offenders and get them blacklisted immediately.