2
I have a dump file (CAP format) of a network traffic capture made with Ubuntu’s tcp dump. Until a certain time, it is a traffic free of attacks. Then, begin a series of attacks of type TCP SYN flooding. My goal is to calculate the entropy of each of the traffic moments (with and without attacks) and compare them.
Does anyone know of a Python library that calculates the entropy of Shannon of a network traffic?
I found the following code, what do you think?
import numpy as np
import collections
sample_ips = [
"131.084.001.031",
"131.084.001.031",
"131.284.001.031",
"131.284.001.031",
"131.284.001.000",
]
C = collections.Counter(sample_ips)
counts = np.array(list(C.values()),dtype=float)
#counts = np.array(C.values(),dtype=float)
prob = counts/counts.sum()
shannon_entropy = (-prob*np.log2(prob)).sum()
print (shannon_entropy)
Imagine I had these Ips only in traffic collected at a certain time.
I would take several trades on different days to see how entropy behaves, thus having several different entropy. What would be the best way to plot a graph using Python to check entropy behavior?
Why don’t you scroll through that file (since you already have it) with python and process what you need to calculate from there?
– Miguel
@Miguel, my problem is to have no idea how to implement the calculation of Shannon entropy. Is there something ready in Python?
– Ed S
See this http://pythonfiddle.com/shannon-entropy-calculation/
– Miguel