lockout is a tool that monitors system logs and dynamically creates
firewall entries when certain criteria are met. Unlike similar systems
that rely on cron jobs (minimum granularity of one minute), lockout
reads a named pipe so responds very quickly when abuse is detected.
The rules as well as firewall setup are fully configurable.
Full instructions can be found here
The source and instructions can be found here