-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect_freq.py
83 lines (60 loc) · 1.77 KB
/
detect_freq.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
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
import numpy as np
import pandas as pd
from datetime import datetime, timedelta
from nfstream import NFStreamer, NFPlugin
import nfstream
time = None
lowflow = 0
freq_alarm = 0
class Frequency(NFPlugin):
def on_init(self, pkt, flow):
global lowflow
global time
global freq_alarm
flow.expiration_id = 0
flow.udps.fr_alarm = False
if flow.bidirectional_duration_ms == 0:
bidir = 0.0001
else:
bidir = flow.bidirectional_duration_ms
frequency = flow.bidirectional_packets/bidir
if frequency > 300:
freq_alarm += 1
time = None
def on_update(self, pkt, flow):
global lowflow
global time
global freq_alarm
if flow.bidirectional_duration_ms == 0:
bidir = 0.0001
else:
bidir = flow.bidirectional_duration_ms
frequency = flow.bidirectional_packets/bidir
if frequency > 300:
freq_alarm += 1
flow.udps.fr_alarm = True
time = None
if time is None:
time = pkt.time
time_diff = pkt.time - time
if time_diff > 10000:
freq_alarm = 0
time = None
mssql_freq = NFStreamer(source="wlp3s0",
udps=Frequency(),
)
comparison_frequency = NFStreamer(source="wlp3s0",
udps=Frequency())
#testing
a = 0
for flow in mssql_freq:
if flow.udps.fr_alarm == True:
a += 1
print("Number of Expirations mssql: ",a)
a = 0
for flow in comparison_frequency:
if flow.udps.fr_alarm == True:
a += 1
print("LowFlow: ",lowflow)
print("Expiration: ",flow.udps.fr_alarm,"\n")
print("Number of Expirations comp: ",a)