Dynamical mean-field approach to Ising models with impurities