|
|
|
@ -7,11 +7,13 @@
|
|
|
|
|
import scapy.all as scapy
|
|
|
|
|
import scapy.contrib.modbus as mb
|
|
|
|
|
|
|
|
|
|
from triPacket import triPacket
|
|
|
|
|
import getpass
|
|
|
|
|
|
|
|
|
|
def decode(pkt):
|
|
|
|
|
if "ModbusADU" in pkt:
|
|
|
|
|
global miniL
|
|
|
|
|
modpkt = pkt["ModbusADU"]
|
|
|
|
|
print(modpkt.payload.name)
|
|
|
|
|
typeCall = ""
|
|
|
|
|
|
|
|
|
|
if "Multiple" in modpkt.payload.name:
|
|
|
|
@ -30,7 +32,6 @@ def decode(pkt):
|
|
|
|
|
typeCall += "r"
|
|
|
|
|
if "Response" in modpkt.payload.name:
|
|
|
|
|
byteCount = modpkt.payload.getfieldval("byteCount")
|
|
|
|
|
print(byteCount,"cc")
|
|
|
|
|
cs = []
|
|
|
|
|
if "C" in typeCall:
|
|
|
|
|
Value = modpkt.payload.getfieldval("coilStatus")
|
|
|
|
@ -42,9 +43,9 @@ def decode(pkt):
|
|
|
|
|
else:
|
|
|
|
|
cs = modpkt.payload.getfieldval("registerVal")
|
|
|
|
|
for j in range(len(cs)):
|
|
|
|
|
bigL.append([miniL[0],cs[j],miniL[2]+j])
|
|
|
|
|
#bigL.append([miniL[0],cs[j],miniL[2]+j])
|
|
|
|
|
triPacket([miniL[0][1],miniL[2]+j,cs[j]],connec)
|
|
|
|
|
miniL = [0,0,0]
|
|
|
|
|
print(bigL)
|
|
|
|
|
else:
|
|
|
|
|
startAddr = modpkt.payload.getfieldval("startAddr")
|
|
|
|
|
miniL[2] = startAddr
|
|
|
|
@ -66,8 +67,9 @@ def decode(pkt):
|
|
|
|
|
cs.extend(k for k in [*bi])
|
|
|
|
|
|
|
|
|
|
for j in range(len(cs)):
|
|
|
|
|
bigL.append([miniL[0],cs[j],addr+j]) # changer 5 pour mettre l'adresse
|
|
|
|
|
print(bigL)
|
|
|
|
|
#bigL.append([miniL[0],cs[j],addr+j]) # changer 5 pour mettre l'adresse
|
|
|
|
|
triPacket([miniL[0][1],addr+j,cs[j]],connec)
|
|
|
|
|
#print(bigL)
|
|
|
|
|
else:
|
|
|
|
|
if "C" in typeCall:
|
|
|
|
|
addr = modpkt.payload.getfieldval("outputAddr")
|
|
|
|
@ -75,9 +77,24 @@ def decode(pkt):
|
|
|
|
|
else:
|
|
|
|
|
addr = modpkt.payload.getfieldval("registerAddr")
|
|
|
|
|
outputValue = modpkt.payload.getfieldval("registerValue")
|
|
|
|
|
bigL.append([miniL[0],outputValue,addr])
|
|
|
|
|
triPacket([miniL[0][1],addr,outputValue],connec)
|
|
|
|
|
#bigL.append([miniL[0],outputValue,addr])
|
|
|
|
|
|
|
|
|
|
#print(bigL)
|
|
|
|
|
bigL = []
|
|
|
|
|
print("In order for data sniffed to be stored inside the database, please register the following :")
|
|
|
|
|
db_host = input('host of the database server : ')
|
|
|
|
|
if not db_host:
|
|
|
|
|
db_host = '192.168.128.141'
|
|
|
|
|
db_name = input('name of the database : ')
|
|
|
|
|
if not db_name:
|
|
|
|
|
db_name = 'dblodufour1'
|
|
|
|
|
db_user = input('login of the user : ')
|
|
|
|
|
if not db_user:
|
|
|
|
|
db_user = 'lodufour1'
|
|
|
|
|
db_password = getpass.getpass('user password : ')
|
|
|
|
|
connec=[db_host,db_name,db_user,db_password]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
miniL = [0,0,0]
|
|
|
|
|
scapy.sniff(iface="lo", prn=decode)
|
|
|
|
|