Graph of a Python denial of service attack

Asked

Viewed 115 times

2

Friends,

I generated the following chart:

Número de conexões por segundo

The code used was the following:

import matplotlib.pyplot as plt
import matplotlib.dates as dates
from datetime import datetime, timedelta

x = []
y = []

dataset = open("./datasetDdos10Abril2017_unixtime_slowloris.csv","r")
##separacao no csv eh por virgulas

for line in dataset:
    line = line.strip() #23,24\n -> 23,24 retira a quebra de linha
    X,Y = line.split(",") #separador eh a virgula
    x.append( float(X))
    y.append(float (Y))

dataset.close()

x1 = [datetime.fromtimestamp(int(d)) for d in x]

plt.gca().xaxis.set_major_formatter(dates.DateFormatter('%m/%d/%Y %H:%M:%S'))

y1 = []
v = 0
for i in sorted(y):
    if(abs(i-v > 50)):
        y1.append(i)
        v = i

plt.plot(x1, y, 'ro')

plt.title("Número de Conexões por segundo: Ataque Sockstress")
plt.ylabel("Número de Conexões por segundo")
plt.xlabel('Tempo')
plt.xticks(x1)
plt.yticks(y1)

#plt.gca().set_ylim([0, 29800])
plt.gcf().autofmt_xdate()
plt.show()

When showing the graph to a teacher, he said that the graph was not very clear and suggested to do it as a bar graph.

Any suggestions on how to better present the data?

How to make a bar chart using Python, like the data below?

The data file (CSV) is available at: https://ufile.io/cnhl5

  • 1

    The bar chart would be much better, I only saw the value of 09:45 after looking at the screen, already with the bar would be much clearer because the bar occupies a much larger space in the graph.

  • 1

    @Tiago Oliveira de Freitas : thank you! Helped a lot to understand the reason!

1 answer

2


Here’s what you can do:

import matplotlib.pyplot as plt
import matplotlib.dates as dates
from datetime import datetime, timedelta

x = []
y = []
with open("./datasetDdos10Abril2017_unixtime_slowloris.csv") as f:
    for l in f:
        X,Y = l.split(",") #separador eh a virgula
        x.append(float(X))
        y.append(float (Y))

x1 = [datetime.fromtimestamp(int(d)) for d in x]
y_pos = [idx for idx, i in enumerate(y)]

plt.gca().xaxis.set_major_formatter(dates.DateFormatter('%m/%d/%Y %H:%M:%S'))

y1 = []
v = 0
y_sorted = sorted(y)
for i in y_sorted:
    if(abs(i-v > 50)):
        y1.append(i)
        v = i

plt.bar(y_pos, y, align='edge', color="blue", alpha=0.5, width=0.5) # <--- EDICAO PRINCIPAL

plt.title("Número de Conexões por segundo: Ataque Sockstress")
plt.ylabel("Número de Conexões por segundo")
plt.xlabel('Tempo')
plt.xticks(y_pos, x1, size='small',rotation=35, ha="right")
plt.yticks(y1)
plt.ylim(ymin=y_sorted[0]-200) # valor minimo do eixo y

plt.show()
  • do you find the bar chart better in this case? I don’t understand why the chart isn’t clear!

  • I sincerely agree with your teacher @Eds, with the balls you can not have as much visual accuracy about the value y of each

  • bar chart would look better?

  • That’s what you asked @Eds to do, so you get two and you ask your teacher about it, and honestly I think, yeah

  • I tried running the code but it is showing the following error: https://ufile.io/mgln3 Could you please help?

  • Try putting # -*- coding: utf-8 -*- in the first of the code, first of all @Eds. That’s because of the special characters, "ç, words with accent, etc..." I think you’re using python 2.x, right?

  • I use both 2.7 and 3.6 but I’ve circled in Python 2.7

  • 1

    now spun! God bless you!

  • I’ve asked another question. If you have time: https://answall.com/questions/231150/gr%C3%a1fico-em-barras-feito-em-python-ficou-estranho-algum-sugest%C3%a3o-de-como-melh

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.