Commit d9c90ff6 authored by Sajana_it20194130's avatar Sajana_it20194130

Upload New File

parent 81cdf8d9
import joblib
import re
import nltk
import numpy as np
nltk.download('stopwords')
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer
from tkinter import messagebox
# Load the dumped models
regressor = joblib.load('random_forest_model.joblib')
cv = joblib.load('count_vectorizer.joblib')
# Function to Clean the texts
def preprocess_text(text):
log = re.sub('[^a-zA-Z0-9]', ' ', text)
log = log.lower()
log = log.split()
ps = PorterStemmer()
log = [ps.stem(word) for word in log if not word in set(stopwords.words('english'))]
log = ' '.join(log)
return log
# Mapping of predictions to respective types
prediction_types = {
0: "Normal",
1: "Wrong Setup",
2: "DDOS",
3: "Data type probing",
4: "Scan Attack",
5: "Man in the Middle"
}
# New traffic insert
new_text = input("Enter the IoT Traffic: ")
preprocessed_text = preprocess_text(new_text)
# Use the loaded CountVectorizer object to transform the preprocessed text into a bag of words representation
new_data_transformed = cv.transform([preprocessed_text]).toarray()
# Make predictions using the loaded model
predictions = regressor.predict(new_data_transformed)
rounded_predictions = np.round(predictions)
predicted_type = prediction_types[int(rounded_predictions[0])]
# Print the predictions
print(rounded_predictions)
# Display a pop-up message with the predicted type
message = f"The predicted traffic type is: {predicted_type}"
messagebox.showinfo("Prediction", message)
#0- 2020 12:37:22.736684743 IST$54$50:02:91:69:66:71$98:22:ef:d5:cc:2f$192.168.0.35$192.168.0.121$6$40$0$49279$80$49279 → 80 [FIN
#1- 2020 12:37:22.860634861 IST$269$50:02:91:69:66:71$98:22:ef:d5:cc:2f$192.168.0.35$192.168.0.121$6$255$215$56127$80$GET /ids/server.php?data=60.00 HTTP/1.1
#2- 2020 13:04:23.345843354 IST$98$64:6e:69:dc:d7:c9$98:22:ef:d5:cc:2f$192.168.0.183$192.168.0.121$1$84$$$$Echo (ping) request id=0x55ce
#3- 2020 12:37:41.624289372 IST$42$98:22:ef:d5:cc:2f$ac:bc:32:c0:21:4b$$$$$$$$Who has 192.168.0.198? Tell 192.168.0.121
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment