Easy to attack and difficult to defend is one of the core issues on network security. Moving target defense is a key technology to enhance network defense capabilities and ensure cyberspace security. At present, most studies on the optimal defense strategy for moving targets defense adopt the classic single/multi-stage game model and Markov game model, which cannot make flexible decisions in continuous real-time network attack and defense confrontation. In order to achieve the real-time selection of the optimal moving target defense strategy, this paper considers that the interdependence between the microscopic individual behavior and the macroscopic communication phenomenon in the network will have impact on the network’s offensive and defense decisions. Based on the research on node-level infectious disease model and differential game theory, a differential game model for moving target defense is proposed. The security state evolution equation and the objective function of offensive and defensive gains are constructed for important nodes in cyberspace. And the open-loop Nash equilibrium solution algorithm is designed to obtain the optimal defense strategy. The simulation results show that this method can effectively defend against network attacks in real-time and can make moving target defense decisions for key network nodes. Finally, based on the experimental results, key recommendations are put forward for the defense of important nodes in the network system.