-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddostest.py
53 lines (41 loc) Β· 1.92 KB
/
ddostest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pandas as pd
from joblib import load
from sklearn import preprocessing
def attack_detection(json_path):
# λ°μ΄ν° λΆλ¬μ€κΈ°
data = pd.read_json(json_path).fillna(0)
# νμν νΉμ±λ§ μ ννμ¬ λ°μ΄ν° μ€λΉ
df = data.dropna()
# "Protocol" μ΄μ μ«μλ‘ λ³ν
protocol_map = {'TCP': 6, 'UDP': 17} # μνλ νλ‘ν μ½ λ° ν΄λΉ μ«μλ‘ λ§€ν
df['Protocol'] = df['Protocol'].map(protocol_map)
# μ μ₯λ λͺ¨λΈ λΆλ¬μ€κΈ°
loaded_model = load('/Users/chonakyung/modelmodel/ddos_detection_model.joblib')
scaler = load('/Users/chonakyung/Desktop/capstone/packet/scaler.joblib')
# νΉμ± μ΄λ¦ μ μ
feature_names = [
'Flow Duration', 'Total Fwd Packets', 'Total Backward Packets', 'Flow Packets/s',
'Flow Bytes/s', 'Avg Packet Size', 'FIN Flag Count', 'SYN Flag Count',
'RST Flag Count', 'PSH Flag Count', 'ACK Flag Count', 'URG Flag Count',
'ECE Flag Count', 'Fwd Packets Length Total', 'Bwd Packets Length Total',
'Flow IAT Mean', 'Flow IAT Std', 'Idle Mean', 'Protocol'
]
# μμΈ‘ν λ°μ΄ν°
sample_data = df[feature_names]
# μμΈ‘ν λ°μ΄ν°μ μ΄ μμλ₯Ό νμ΅ν λ μ¬μ©λ μμμ λμΌνκ² λ§λ€κΈ°
sample_data = sample_data.reindex(columns=scaler.feature_names_in_, fill_value=0)
# μ€μΌμΌλ¬λ‘ νμ΅ λ°μ΄ν°μ²λΌ λ³ν
sample_data_scaled = scaler.transform(sample_data)
# λͺ¨λΈμ μμΈ‘ μν
prediction = loaded_model.predict(sample_data_scaled)
print("Prediction:", prediction)
return prediction
# μμ μ¬μ©
json_path = '/Users/chonakyung/modelmodel/packet_info.json'
# json_path = 'normal_json/1.json'
predictions = attack_detection(json_path)
# μμ μ¬μ©
# if __name__ == "__main__":
# json_path = '/Users/chonakyung/modelmodel/packet_info.json'
# predictions = attack_detection(json_path)
# print(predictions)