aboutsummaryrefslogtreecommitdiff
path: root/analyse/insertpaq.py
blob: dee7571cccd67416314410d6d3f9e7b541434358 (plain)
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
#!/usr/bin/python
# coding: utf-8

import psycopg2


# read a text file as a list of lines
# find the last line, change to a file you have
LireHeureTCP = open ( '/tmp/heuretcp.txt',"r" )
LireProtocoleTCP = open ( '/tmp/protocoletcp.txt',"r" )
LireIPSRCTCP = open ( '/tmp/ipsrctcp.txt',"r" )
LirePortSRCTCP = open ( '/tmp/portsrctcp.txt',"r" )
LireIPDSTTCP = open ( '/tmp/ipdsttcp.txt',"r" )
LirePortDSTTCP = open ( '/tmp/portdsttcp.txt',"r" )

LireHeureUDP = open ( '/tmp/heureudp.txt',"r" )
LireProtocoleUDP = open ( '/tmp/protocoleudp.txt',"r" )
LireIPSRCUDP = open ( '/tmp/ipsrcudp.txt',"r" )
LirePortSRCUDP = open ( '/tmp/portsrcudp.txt',"r" )
LireIPDSTUDP = open ( '/tmp/ipdstudp.txt',"r" )
LirePortDSTUDP = open ( '/tmp/portdstudp.txt',"r" )


DerniereLigneHeureTCP = LireHeureTCP.read().splitlines()
LireHeureTCP.close()

DerniereLigneProtocoleTCP = LireProtocoleTCP.read().splitlines()
LireProtocoleTCP.close()

DerniereLigneIPSRCTCP = LireIPSRCTCP.read().splitlines()
LireIPSRCTCP.close()

DerniereLignePortSRCTCP = LirePortSRCTCP.read().splitlines()
LirePortSRCTCP.close()

DerniereLigneIPDSTTCP = LireIPDSTTCP.read().splitlines()
LireIPDSTTCP.close()

DerniereLignePortDSTTCP = LirePortDSTTCP.read().splitlines()
LirePortDSTTCP.close()

#Coucou

DerniereLigneHeureUDP = LireHeureUDP.read().splitlines()
LireHeureUDP.close()

DerniereLigneProtocoleUDP = LireProtocoleUDP.read().splitlines()
LireProtocoleUDP.close()

DerniereLigneIPSRCUDP = LireIPSRCUDP.read().splitlines()
LireIPSRCUDP.close()

DerniereLignePortSRCUDP = LirePortSRCUDP.read().splitlines()
LirePortSRCUDP.close()

DerniereLigneIPDSTUDP = LireIPDSTUDP.read().splitlines()
LireIPDSTUDP.close()

DerniereLignePortDSTUDP = LirePortDSTUDP.read().splitlines()
LirePortDSTUDP.close()


#print "Heure TCP:"
a = str(DerniereLigneHeureTCP[-1])

#print "Protocole TCP:"
b = str(DerniereLigneProtocoleTCP[-1])

#print "IP Source TCP:"
c = str(DerniereLigneIPSRCTCP[-1])

#print "Port Source TCP:"
d = str(DerniereLignePortSRCTCP[-1])

#print "IP Destination TCP:"
e = str(DerniereLigneIPDSTTCP[-1])

#print "Port Destination TCP:"
f = str(DerniereLignePortDSTTCP[-1])


#Re coucou

#print "Heure UDP:"
z = str(DerniereLigneHeureUDP[-1])

#print "Protocole UDP:"
y = str(DerniereLigneProtocoleUDP[-1])

#print "IP Source UDP:"
x = str(DerniereLigneIPSRCUDP[-1])

#print "Port Source UDP:"
w = str(DerniereLignePortSRCUDP[-1])

#print "IP Destination UDP:"
v = str(DerniereLigneIPDSTUDP[-1])

#print "Port Destination UDP:"
u = str(DerniereLignePortDSTUDP[-1])


def connexionBD():
	connexion=psycopg2.connect ("host='localhost' dbname='atsdb' user='atsuser' password='123456'")
	return connexion

conn=connexionBD()
cur=conn.cursor()
	
#sql="""
#insert into paquet(heure,protocole,ip_source,ip_destination,port_source,port_destination) values ('{}','{}','{}','{}','{}','{}');
#insert into paquet(heure,protocole,ip_source,ip_destination,port_source,port_destination) values ('{}','{}','{}','{}','{}','{}');
#""".format(a,b,c,e,d,f,z,y,x,v,w,u)

cur.execute("INSERT INTO paquet (heure,protocole,ip_source,ip_destination,port_source,port_destination) VALUES (%s, %s, %s, %s, %s, %s)",
        (a, b, c, e, d, f))
cur.execute("INSERT INTO paquet (heure,protocole,ip_source,ip_destination,port_source,port_destination) VALUES (%s, %s, %s, %s, %s, %s)",
        (z, y, x, v, w, u))

#cur.execute(sql)

conn.commit()
conn.close()