hiany firewall worth it's name should be able to do this. in fact, that is one of several things that a firewall was designed to do.
also, you are stopping this traffic at the application, which is good; but you'd prolly be better off stopping it at the network interface [using a firewall, for instance].
of course, firewalls have their own complexity ... good luck!