As Internet technology advances, cyberattacks crop up, threatening Internet safety. In the present work, an active defense mechanism for emails and webpage access is proposed, which classifies the textual contents and HTML tag sequences extracted from emails and webpages by BERT algorithms. For model training, down-sampling and model fusion are employed to process imbalanced datasets, and the performance of multiple pretrained models is compared. By combining e-mail and URLs filtering system, we build an active defense framework for terminal access based on BERT algorithm. It was found that deep learning provides a decision-making basis for enterprises to configure their security policy settings and transfer the predicted threats to security terminals to preclude security risks.