drake50 has asked for the wisdom of the Perl Monks concerning the following question:

I've noticed some sites, like slashdot and freshmeat for example use code that allows them to ban by ip. So if you are going on vacation and you want to download their entire site at some point they cut you off and save their bandwidth for another day. I'd like to have something like this for my website.

Question 1: Is there something like this already available?

Question 2: If not, how hard would it be to write this in perl?

Replies are listed 'Best First'.
Re: IP ban for apache
by thpfft (Chaplain) on Mar 15, 2003 at 22:54 UTC

    Apache::Throttle is probably the most elegant solution, if you're mod_perled up - which you will be, if load is such a big deal - and as ever, merlyn has a column on the subject. there's good stuff in the mod_perl cookbook too, iirc.

    update: The action taken when the throttle is triggered is up to you, so if you really want to ban someone it would be easy enough to to redirect every subsequent request from that particular IP address to a page that told them off and perhaps offered a chance to appeal the sentence. Or drop the address into hosts.deny, if you really don't like them. Address != user, though...

•Re: IP ban for apache
by merlyn (Sage) on Mar 15, 2003 at 22:54 UTC
      Okay, it looks like I can use Apache::Traffic to see how many bytes or pages someone has viewed/dloaded. Now I decide I want to ban them. How can I use the allow/deny directives to do that on the fly? Doesn't apache have to be restarted to use the new values?

        $ apachectl graceful

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: IP ban for apache
by data64 (Chaplain) on Mar 15, 2003 at 22:22 UTC

    A very basic system can be implemented using the allow/deny directives.


    Just a tongue-tied, twisted, earth-bound misfit. -- Pink Floyd

Re: IP ban for apache
by tachyon (Chancellor) on Mar 16, 2003 at 06:29 UTC

    Another somewhat left field solution is to put a squid proxy cache on port 80 with the desired acl list. Squid does acls to death. You then redirect from the squid to your server (which now lives on another port - say 81). There are some speed advantages to this approach as you serve a lot of requests from the squid cache (which is of course designed to be fast) thus unloading your httpd. There are claims of an order of magnitude ie 10x speed increase.... Full details at squid-cache.org See the httpd-accelerator mode section in the FAQ.

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print