diff --git a/src/decoderBrut.py b/src/decoderBrut.py index e83211d..9eb65f2 100644 --- a/src/decoderBrut.py +++ b/src/decoderBrut.py @@ -116,5 +116,11 @@ if not db_user: db_password = getpass.getpass('user password : ') connec=[db_host,db_name,db_user,db_password] +# si register 5 = 55 et coil 3 = 1 et coil 12 = 0 : +# ecriture sur le registre 8 à 72 ou coil 9 à 1 impossibles +# if ['r',5,55] and ['c',3,1] and ['c',12,0] and ecriture ['r',8,72]: + #bloquer ecriture +# ecrire registre 5 72,4,4,55,4 + scapy.sniff(iface="lo", prn=decode) diff --git a/src/ecritureBDD.py b/src/ecritureBDD.py index 901fbbe..75c14fb 100644 --- a/src/ecritureBDD.py +++ b/src/ecritureBDD.py @@ -2,13 +2,20 @@ import psycopg2 as psy import pandas as pd import getpass -def ecritureBDD(typeMem,addresse,valeur,connec): +def verifRegle(a): + return True + +def ecritureBDD(lStatus,connec): co = None try: co = psy.connect(host=connec[0],database=connec[1],user=connec[2],password=connec[3]) cur = co.cursor() - cur.execute("INSERT INTO Status VALUES (%s,%s,%s ) ON CONFLICT (addresse,type) DO UPDATE SET valeur=%s;",(addresse,typeMem,valeur,valeur)) - co.commit() + for i in lStatus: + cur.execute("INSERT INTO Status VALUES (%s,%s,%s ) ON CONFLICT (addresse,type) DO UPDATE SET valeur=%s;",(i[1],i[0],i[2],i[2])) + if verifRegle(co): + co.commit() + else: + co.rollback() cur.close() except(Exception,psy.DatabaseError) as error: print(error) diff --git a/src/triPacket.py b/src/triPacket.py index b5309d8..f84d815 100644 --- a/src/triPacket.py +++ b/src/triPacket.py @@ -1,18 +1,22 @@ from ecritureBDD import ecritureBDD -def triPacket(lPkt,connec): +def decoupePacket(lPkt): if type(lPkt)!=list: print('pas liste') return if len(lPkt)==0: - print('vide') + print('liste vide') return if len(lPkt)==1: - triPacket(lPkt[0],connec) - return + return decoupePacket(lPkt[0]) if len(lPkt)==3 and type(lPkt[0])==str: - ecritureBDD(lPkt[0],int(lPkt[1]),int(lPkt[2]),connec) - return + return [[lPkt[0],int(lPkt[1]),int(lPkt[2])]] else: + l=[] for i in lPkt: - triPacket(i,connec) + l+=decoupePacket(i) + return l + +def triPacket(lPkt,connec): + lNettoyee=decoupePacket(lPkt) + ecritureBDD(lNettoyee,connec)