#!/usr/bin/env python
# -*- coding: utf-8 -*-

#https://scapy.readthedocs.io/en/latest/api/scapy.packet.html#scapy.packet.Packet
#https://scapy.readthedocs.io/en/latest/api/scapy.contrib.modbus.html

import scapy.all as scapy
import scapy.contrib.modbus as mb

def decode(pkt):
    if "ModbusADU" in pkt:
        miniL=[]
        cc = pkt["ModbusADU"]
        print(cc.payload.name)
        for i in cc.payload.fields:
            miniL.append(cc.payload.getfieldval(i))
            print(i,cc.payload.getfieldval(i))
        bigL.append(miniL)
    print("fin de decode")
bigL = []
scapy.sniff(iface="lo", prn=decode)
