This article aims to analyze H∞ stability of a class of networked control systems (NCSs) under random denial of service (DoS) attacks and design a sampled-data-based state feedback security controller to mitigate the influence of attacks. Different from the existing random attacks, the information about the maximum duration time of DoS attacks can be captured by introducing a predesigned logical processor. Then, based on the periodic sampling technique, the probability of attack occurrence and the resultant number of maximum allowable consecutive packet dropouts can be calculated, which is quite significant to investigating the security problem of NCSs. A DoS-dependent security controller which makes full use of the attack probability information and the number of attack-induced packet dropouts is designed. A novel networked sampled-data system model is first established that enables us to deal with the random DoS attacks phenomena and the time-varying delay induced by attacks under a uniform framework. By structuring a suitable Lyapunov-Krasovskii functional, the relationship between mean square asymptotic stability and attack characteristics is obtained. Finally, the reliability and applicability of the presented control strategy in eliminating the influence of DoS attacks are validated by two practical engineering applications.