With the continuous updating of intrusion methods, the accuracy of traditional intrusion detection methods decreases and the detection time is extended, which has been unable to meet the requirements of network defense. To this end, an improved K-means data clustering algorithm was proposed to cope with the escalating network intrusion behavior. Firstly, the values were converted based on firewall logs, and then particle swarm optimization algorithm was used to obtain the optimal initial clustering center, so as to improve the K-means data clustering algorithm;Finally, the calculated eigenvalue were taken as the input item to achieve accurate detection of the network intrusion behavior. The results show that the Davies-Bouldin Index of the improved K-means algorithm is smaller than that before the improvement, which is less than 0. 6, reaching the purpose of improvement. The accuracy rate of each sample of the improved K-means algorithm is higher than 90%, relatively higher, and the detection time is less than 10 s, relatively shorter. This indicate that the research method can complete more accurate network intrusion detection with high efficiency.