From b1f7c1a9f501cd005a5fcc6556bdd3bf37bceea8 Mon Sep 17 00:00:00 2001 From: Luneji <61687883+Luneji@users.noreply.github.com> Date: Tue, 12 May 2020 11:22:52 +0200 Subject: Update tapdanlfon.py --- analyse/tapdanlfon.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/analyse/tapdanlfon.py b/analyse/tapdanlfon.py index 5263af4..eb0b047 100644 --- a/analyse/tapdanlfon.py +++ b/analyse/tapdanlfon.py @@ -1,6 +1,14 @@ #!/usr/bin/python # coding: utf-8 + +import psycopg2 + + +def connexionBD(): + connexion=psycopg2.connect ("host='localhost' dbname='atsdb' user='atsuser' password='123456'") + return connexion + # 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" ) @@ -55,7 +63,6 @@ LireIPDSTUDP.close() DerniereLignePortDSTUDP = LirePortDSTUDP.readlines() LirePortDSTUDP.close() - #print "Heure TCP:" a = DerniereLigneHeureTCP[-1] @@ -75,8 +82,6 @@ e = DerniereLigneIPDSTTCP[-1] f = DerniereLignePortDSTTCP[-1] -insert into paquet(heure,protocole,ip_source,ip_destination,port_source,port_destination) values (a,b,c,e,d,f); - #Re coucou #print "Heure UDP:" @@ -97,4 +102,19 @@ v = DerniereLigneIPDSTUDP[-1] #print "Port Destination UDP:" u = DerniereLignePortDSTUDP[-1] +print a,b,c +#sql part + +conn=connexionBD() +cur=conn.cursor() + +sql="""insert into paquet(heure,protocole,ip_source,ip_destination,port_source,port_destination) values (a,b,c,e,d,f); + insert into paquet(heure,protocole,ip_source,ip_destination,port_source,port_destination) values (z,y,x,v,w,u); +""" + +cur.execute(sql) +conn.commit() +data=cur.fetchall() + +conn.close() -- cgit v1.2.3