How to set up automatic blocking of a bots?

The logs contain a lot of requests from unknown ip addresses to non-existent pages, which gives them a 404 error. Is it possible to block automaticly such ip addresses with frequent requests?