-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpage.html
More file actions
235 lines (225 loc) · 9.1 KB
/
webpage.html
File metadata and controls
235 lines (225 loc) · 9.1 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Network Traffic Prediction</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
padding-top: 20px;
background-color: #f3f3f3;
color: #333;
}
.container {
max-width: 700px;
width: 100%;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #fff;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
color: #333;
font-weight: bold;
margin-bottom: 20px;
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
}
.form-group {
display: flex;
flex-direction: column;
}
label {
font-weight: bold;
margin-bottom: 5px;
font-size: 14px;
color: #555;
}
input[type="number"] {
padding: 8px;
border-radius: 4px;
border: 1px solid #ccc;
font-size: 14px;
width: 100%;
}
input[type="number"]:invalid {
border-color: rgb(0, 0, 0);
}
button {
width: 100%;
padding: 12px;
font-size: 16px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin-top: 20px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
.result {
margin-top: 20px;
text-align: center;
font-size: 18px;
color: #333;
}
.loading {
text-align: center;
font-size: 18px;
color: #007bff;
}
</style>
</head>
<body>
<div class="container">
<h1>Network Traffic Prediction</h1>
<form id="predictionForm">
<div class="form-grid">
<!-- All form fields included here -->
<div class="form-group">
<label for="tcp_srcport">TCP Source Port</label>
<input type="number" id="tcp_srcport" name="tcp_srcport" required>
</div>
<div class="form-group">
<label for="tcp_dstport">TCP Destination Port</label>
<input type="number" id="tcp_dstport" name="tcp_dstport" required>
</div>
<div class="form-group">
<label for="ip_proto">IP Protocol</label>
<input type="number" id="ip_proto" name="ip_proto" required>
</div>
<div class="form-group">
<label for="frame_len">Frame Length</label>
<input type="number" id="frame_len" name="frame_len" required>
</div>
<div class="form-group">
<label for="tcp_flags_syn">TCP Flags SYN</label>
<input type="number" id="tcp_flags_syn" name="tcp_flags_syn" required>
</div>
<div class="form-group">
<label for="tcp_flags_reset">TCP Flags RESET</label>
<input type="number" id="tcp_flags_reset" name="tcp_flags_reset" required>
</div>
<div class="form-group">
<label for="tcp_flags_push">TCP Flags PUSH</label>
<input type="number" id="tcp_flags_push" name="tcp_flags_push" required>
</div>
<div class="form-group">
<label for="tcp_flags_ack">TCP Flags ACK</label>
<input type="number" id="tcp_flags_ack" name="tcp_flags_ack" required>
</div>
<div class="form-group">
<label for="ip_flags_mf">IP Flags MF</label>
<input type="number" id="ip_flags_mf" name="ip_flags_mf" required>
</div>
<div class="form-group">
<label for="ip_flags_df">IP Flags DF</label>
<input type="number" id="ip_flags_df" name="ip_flags_df" required>
</div>
<div class="form-group">
<label for="ip_flags_rb">IP Flags RB</label>
<input type="number" id="ip_flags_rb" name="ip_flags_rb" required>
</div>
<div class="form-group">
<label for="tcp_seq">TCP Sequence</label>
<input type="number" id="tcp_seq" name="tcp_seq" required>
</div>
<div class="form-group">
<label for="tcp_ack">TCP Acknowledgment</label>
<input type="number" id="tcp_ack" name="tcp_ack" required>
</div>
<div class="form-group">
<label for="packets">Packets</label>
<input type="number" id="packets" name="packets" required>
</div>
<div class="form-group">
<label for="bytes">Bytes</label>
<input type="number" id="bytes" name="bytes" required>
</div>
<div class="form-group">
<label for="tx_packets">Tx Packets</label>
<input type="number" id="tx_packets" name="tx_packets" required>
</div>
<div class="form-group">
<label for="tx_bytes">Tx Bytes</label>
<input type="number" id="tx_bytes" name="tx_bytes" required>
</div>
<div class="form-group">
<label for="rx_packets">Rx Packets</label>
<input type="number" id="rx_packets" name="rx_packets" required>
</div>
<div class="form-group">
<label for="rx_bytes">Rx Bytes</label>
<input type="number" id="rx_bytes" name="rx_bytes" required>
</div>
</div>
<button type="submit">Submit</button>
</form>
<div id="loadingMessage" class="loading" style="display: none;">Submitting...</div>
<div class="result" id="result"></div>
</div>
<script>
document.getElementById('predictionForm').addEventListener('submit', async function(event) {
event.preventDefault();
// Show loading message
document.getElementById('loadingMessage').style.display = 'block';
const formData = {
"tcp.srcport": parseInt(document.getElementById('tcp_srcport').value),
"tcp.dstport": parseInt(document.getElementById('tcp_dstport').value),
"ip.proto": parseInt(document.getElementById('ip_proto').value),
"frame.len": parseInt(document.getElementById('frame_len').value),
"tcp.flags.syn": parseInt(document.getElementById('tcp_flags_syn').value),
"tcp.flags.reset": parseInt(document.getElementById('tcp_flags_reset').value),
"tcp.flags.push": parseInt(document.getElementById('tcp_flags_push').value),
"tcp.flags.ack": parseInt(document.getElementById('tcp_flags_ack').value),
"ip.flags.mf": parseInt(document.getElementById('ip_flags_mf').value),
"ip.flags.df": parseInt(document.getElementById('ip_flags_df').value),
"ip.flags.rb": parseInt(document.getElementById('ip_flags_rb').value),
"tcp.seq": parseInt(document.getElementById('tcp_seq').value),
"tcp.ack": parseInt(document.getElementById('tcp_ack').value),
"Packets": parseInt(document.getElementById('packets').value),
"Bytes": parseInt(document.getElementById('bytes').value),
"Tx Packets": parseInt(document.getElementById('tx_packets').value),
"Tx Bytes": parseInt(document.getElementById('tx_bytes').value),
"Rx Packets": parseInt(document.getElementById('rx_packets').value),
"Rx Bytes": parseInt(document.getElementById('rx_bytes').value)
};
try {
const response = await fetch('http://127.0.0.1:8000/predict', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
const result = await response.json();
// Hide loading message and show result
document.getElementById('loadingMessage').style.display = 'none';
document.getElementById('result').innerHTML = `
<strong>Predicted Class:</strong> ${result.predicted_class} <br>
<strong>Class Label:</strong> ${result.class_label}
`;
} catch (error) {
// Hide loading message and show error message
document.getElementById('loadingMessage').style.display = 'none';
document.getElementById('result').innerHTML = "An error occurred. Please try again.";
console.error("Error:", error);
}
});
</script>
</body>
</html>