How to stop pesky spam by blocking IP addresses from visiting your blog

I had a lot of spam from a particular IP *cough* 194.8.75.149 *cough* so I wanted to stop access to the site from the IP. Using only 3 lines in my htaccess file, I managed to cut down my spam by 4 an hour!

By Clinton Montague

Wow, that’s a long title, but it’s worth it! This is just a quick blog post really to vent a bit of pseudo-anger.

The problem

I have been getting a hell of a lot of spam from a certain IP address, I’m not one to point fingers, so I won’t tell you what it is *cough* 194.8.75.149 *cough*. And I’m talking about 4 or 5 spam comments an hour (which I know, on the grand scheme of things is nothing, but it’s quite over-whelming for a small time blogger like myself!). So either it’s a bot, or a person who has an extremely large supply of non-prescription drugs in his garage. Either way, I don’t want them posting spam comments on my blog. If it’s a bot, it won’t really care; if it’s a real person, f@*% you, if all you can do is post spam comments, then I don’t want you reading my blog anyway!

The solution

I’m simply going to use my great pal .htaccess to deny access to my site from the spamming IP. I realise that this is not a great solution, after all, it’s unlikely that you’ll be able to keep on-top of every single IP address of spammers, but it’s an insight into the principles, and a great way of getting rid of single troublesome IPs.

So here’s the code:

1
2
3
Order Allow,Deny
Deny from 194.8.75.149
Allow from all

Which is as easy to understand as it looks – just give it the IP you don’t want to have access to your site, and tell apache to deny access. This is actually remarkably powerful, you can use it to conditionally serve CSS for different browsers (based on browser string), stop image hot-linking, and much much more.

Dude, just use Akismet

Yeah, I know, you’re right, Akismet is awesome! If you don’t have it installed on your blog, you should. It checks a huge (and frequently updated) database to see if a new comment looks like spam, and if so, puts it into a spam queue. But I just like to keep on top of my spam queue and keep it empty. So getting rid of this troublesome IP will save me a bit of time and trouble :)

</rant>

Have you had similar spamming IP problems? What were the addresses. Go on, name and shame!

Tags: , , , ,

7 Comments

  1. Oli Long added these wise words on February 16, 2009 | Permalink

    Interesting, although all the sites we do run on MS servers (I know I know!)

    What are your thoughts on Captcha?

    O.

  2. Clinton Montague added these wise words on February 16, 2009 | Permalink

    Thanks for the comment Oli! Well, that’s what you get for not running Linux :p although I believe that there are similar technologies on IIS.

    And onto THAT question – personally I think there are better ways to prevent spam than presenting the user with an unreadable, mangled word in an image. (for example, see the simple maths question on this comment form). One way that really gets me excited at the moment is adding an extra form field then, hiding it with CSS (obviously with a relevant descriptive comment for non css users) which is supposed to be submitted empty. Spambots will see it and naturally fill it in, so server side if the field has a value, it’s probably a spam submission.

    Having said that, it’s not something I’ve done a lot of research into, so may well be flawed. Anyone tried this/know any more about it?

  3. Kevin added these wise words on May 14, 2009 | Permalink

    I’m not so sure about the numeric problems. JavaScript engines are perfectly capable of evaluating simple math problems, and even some more complex ones. This page gives a good demonstration of the eval() function in javascript.

    http://ai.ijs.si/Mezi/pedagosko/javascript/izracun.html

    Regardless, CAPTCHA’s that are image based are more likely to work, I’m surprised I haven’t seen a lot of bots get around the math problem.

  4. AndrewBoldman added these wise words on June 4, 2009 | Permalink

    da best. Keep it going! Thank you

  5. MichaellaS added these wise words on July 23, 2009 | Permalink

    tks for the effort you put in here I appreciate it!

  6. Mary-Joe added these wise words on July 30, 2009 | Permalink

    I wanted to introduce myself, hello! Hope I get famous soon like you!!

  7. Clinton Montague added these wise words on August 2, 2009 | Permalink

    @Mary-joe I don’t think I’m famous, to be frightfully honest. You too could set up a blog which gets as much spam (but I guess you’re more interested in REAL traffic, like myself ;) ) as slightlymore. The answer is to write regular and relevant content, then the googlers (and indeed spammers) will arrive!

    Good luck!

One Trackback

  1. [...] more: How to stop pesky spam by blocking IP addresses from visiting your blog Share and [...]

Me on the intertubes

It wouldn't be right to have a web site, be a nerd, and not take this opportunity for a bit of shameless pluggery.

If you like all these weird and magic internet page things, you should try Coaster Nerd, Oxford Bloggers or, if you'd really like some unexplainable sourcery, is it the weekend yet.

Also you should follow me on Twitter ;)

Where to find me

I can be found fairly regularly at Oxford Geek Nights, OxTuttle and other general nerding out activities in and around Oxford.

I am also often found in my natural habitat which is anywhere that you can find an adreneline machine. I frequent English theme parks more often than is healthy, and take trips abroad to sample foreign rides.

From the aviary

Was having a decidedly crap day of development. Just got much better. It's nice when things go your way. #win 1 day ago

Subscribe

Slightlymore Posts RSS feed

Comedy disclaimer

These posts were written at the time of writing and may not still be accurate or reflect my opinions any more. In fact, they may not even be correct or representative at the time of writing. You see, when I write, I just write. I don't do that thing which they always told you to do at school and plan what you want to write first. Because of this, there will almost certainly be a load of typos, grammar errors and incorrect facts and references. If this makes you feel queasy, I apologise that you had to get to the bottom of the page to read this, and hope that some day, you'll learn to forgive me.

What's this site?

Slightlymore started off all too formally for my liking. In the depths of the archives, you'll find tutorials. However if you read the more recent posts, you'll find them a lot more playful and about fun and interesting stuff.

Annoyingly difficult to use tag cloud