Hackerscanconductmoredestructivecyber-attacksthankstotherapidspread of Internet of Things (IoT) devices, posing significant security risks for users. Through a malicious process, the attacker intended to exhaust the capital of the target IoT network. Researchers and company owners are concerned about the reliability of IoT networks, which is taken into account because it has a significant impact on the delivery of facilities provided by IoT systems and the security of user groups. The intrusion prevention system ensures that the network is protected by detecting malicious activity. In this paper, the focus is on predicting attacks and distinguishing between normal network use and network exploitation for intrusion and network attack and we will use Swarm Intelligence (SI) which is one of the types of artificial intelligence (AI) that we harness to choose features to determine the task of them and specifically we will use an algorithm Meerkat Clan (MCA) for this purpose, as this research suggested a modified IDS in machine learning (ML) based IoT environments to identify features and these features will be input into Random Forest algorithm. The IoTID20 dataset is used where nominal traits are removed, so the final dataset contains 79 traits. The data set contains three categories: the label that identifies whether it is a natural use or exploitation, the category that characterizes the type of exploitation, and the subcategory that describes that exploitation more accurately. The number of trees in a random forest (RF) classifier for binary, class, and subclass will be determined by the experiment. The trained classifier is then tested and the approach achieves 100% accuracy for binary target prediction, 96.5% for category and accuracy ranges of 83.7% for sub-category target prediction. The proposed system is evaluated and compared with previous systems and its performance is shown through the use of confusion matrix and others.