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

I’m new to perl and I’m seeking perl monks wisdom I’m desperate. We have apache server and it handles multiple request from multiple users then directs it to a java application that handles the requests, but lately we been getting to many requests from couple of IP addresses. I want to block the IP if too many request comes (ex: If the allowed transaction for second (TPS) from an IP is 10 and if more than that comes I want to block that IP for some time). The idea I’m having is to write a log in the java application and by reading the log to filter the IP. I don’t have any clue will it work or is there a better method. Can anyone help me please? Thank you in advance.

Replies are listed 'Best First'.
Re: IP traffic filter
by Corion (Patriarch) on Sep 07, 2009 at 08:19 UTC

    It seems that Algorithm::FloodControl was written for just that purpose. You would give it a limit_name of the requesting IP and it tells you whether that IP made too many requests already. If so, you could insert the IP address and an expiry time into a database table and reject all requests from that IP until the expiry time is reached.

Re: IP traffic filter
by moritz (Cardinal) on Sep 07, 2009 at 08:16 UTC
    This sounds like something best done on the web server level. A quick search for apache limit connections per ip seems to produce quite useful results - I hope one of them is viable for you.
    Perl 6 - links to (nearly) everything that is Perl 6.
Re: IP traffic filter
by Anonymous Monk on Sep 07, 2009 at 08:18 UTC
Re: IP traffic filter
by newPerlr (Novice) on Sep 07, 2009 at 08:38 UTC
    The thing is apache cannot read from the database, database has the limits for the IPs. Algorithm::Floodcontrol seems to be a good idea.
    Thank you Corion. If anyone has more ideas I will appreciate it. Thank you all who replied.