Browse Source

ajout du script genTrafic.py pour générer du trafic sur la journée.
part du l'UnitTest

Citnop 3 years ago
parent
commit
e9e2eb05af
2 changed files with 36 additions and 0 deletions
  1. 34 0
      genTrafic/genTrafic.py
  2. 2 0
      preparser/acsvify.l

+ 34 - 0
genTrafic/genTrafic.py

@@ -0,0 +1,34 @@
1
+#!/usr/bin/python3
2
+#-*- coding: utf-8 -*-
3
+
4
+import os
5
+import re
6
+import datetime
7
+
8
+#~ ajd = datetime.date.today()
9
+sec = int(datetime.date.today().strftime("%s"))
10
+#~ ajd1 = datetime.datetime.fromtimestamp(sec).strftime('%Y-%m-%d %H:%M:%S')
11
+
12
+
13
+IPsrc = input("IP source : ")
14
+IPdst = input("IP destination : ")
15
+f = '/home/administrateur/traficTest.txt'
16
+
17
+
18
+with open(f, 'w') as fw:
19
+    for i in range(86400):
20
+        #~ pq = "2016-09-18 14:21:45.244     0.000 TCP       88.224.34.18:443   ->     192.168.116.45:55817        1       52     1"
21
+        pq = ""
22
+        pq += datetime.datetime.fromtimestamp(sec+i).strftime('%Y-%m-%d %H:%M:%S')
23
+        pq += ".000     1.000 TCP       "
24
+        pq += IPsrc
25
+        pq += ":443"
26
+        pq += "   ->     "
27
+        pq += IPdst
28
+        pq += ":2048"
29
+        pq += "        1       "
30
+        pq += str((i//3600)*10**5)
31
+        pq += "     1"
32
+        fw.write(pq)
33
+
34
+

+ 2 - 0
preparser/acsvify.l

@@ -106,6 +106,7 @@ FLOAT               [0-9]+[.][0-9]+
106 106
 ENTETE              Date[ ]first[ ]seen[ ]+Duration[ ]Proto[ ]+Src[ ]IP[ ]Addr[:]Port[ ]+Dst[ ]IP[ ]Addr[:]Port[ ]+Packets[ ]+Bytes[ ]Flows
107 107
 SPACE               [ ]
108 108
 MEGA                [0-9]+[.][0-9][ ]M
109
+GIGA                [0-9]+[.][0-9][ ]G
109 110
 SPACES              [ ][ ]+
110 111
 DATE                [0-9][0-9][0-9][0-9][-][0-1][0-9][-][0-3][0-9]
111 112
 HOUR                [0-2][0-9][:][0-6][0-9][:][0-6][0-9][.][0-9]{1,3}
@@ -123,6 +124,7 @@ UNWANTED            ^[a-zA-Z]+([ ][a-zA-Z]+)*[:].*$
123 124
 {IPV4PORT}            { echo("IP"); }
124 125
 {UNWANTED}            ;
125 126
 {MEGA}                { echoM(); }
127
+{GIGA}                { echoG(); }
126 128
 {FLOAT}               { echo("NUM"); }
127 129
 {INT}                 { echo("NUM"); }
128 130
 {SPACES}              { blank(); }