You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
987 B

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import scapy.all as scapy
import scapy.contrib.modbus as mb
valeursPropres={}
valeursPasPropres=[]
machin=["","",""]
def decode(pkt):
prt=0
cle=["",""]
f=open("truc.txt","w")
if "ModbusADU" in pkt:
grPkt=pkt["ModbusADU"].show(dump=True)
lPkt=grPkt.splitlines()
for i in lPkt:
if "Addr" in i:
print(i)
addresse=i[17:]
cle[1]=addresse
machin[1]=addresse
if "Write" in i or "Read" in i:
print(i)
if "Coil" in i:
cle[0]="C"
machin[0]="C"
else:
cle[0]="R"
machin[0]="R"
if "Value" in i or "coilStatus" in i or "registerVal" in i:
print(i)
machin[2] = i[-5:]
if "" not in machin:
print(machin)
scapy.sniff(iface="lo", prn=decode)