Automatically modify iptables based on Apache log data to block badly behaved clients

Solution 1:

You can use something like fail2ban, which IIRC, has an Apache log checker built in.

Solution 2:

You might want to consider using iptables to rate-limit incoming connections. Which in its most basic setting will give you the ability to limit incoming connections to a number per minute.

For example, you might want to only allow 10 pings per minute from a single IP address. It does get a little more sophisticated than that, with the option to set burst limits on top of long term average limits.

Some good instructions on setting it up http://kevin.vanzonneveld.net/techblog/article/block_brute_force_attacks_with_iptables/