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.
45 lines
1.3 KiB
45 lines
1.3 KiB
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import scapy.all as scapy
|
|
import scapy.contrib.modbus as mb
|
|
|
|
def decode(pkt):
|
|
prt=0
|
|
addr,value = "",""
|
|
bigL = [ ]
|
|
f=open("truc.txt","w")
|
|
if "ModbusADU" in pkt:
|
|
grPkt=pkt["ModbusADU"].show(dump=True)
|
|
lPkt=grPkt.splitlines()
|
|
for i in lPkt:
|
|
if "###" in i:
|
|
#if addr!="" and value!="":
|
|
#print("addr=",addr,"value=",value)
|
|
prt=0
|
|
typResp=""
|
|
if "Coil" in i:
|
|
prt=1
|
|
typResp="c"
|
|
if len(miniL)==0:
|
|
miniL.append(typResp)
|
|
#if prt==1:
|
|
#print(i)
|
|
elif "startAddr" in i or "outputAddr" in i:
|
|
addr = i[i.find("=")+2:]
|
|
miniL.append(addr)
|
|
#print(addr)
|
|
elif "coilStatus" in i:
|
|
value = i[i.find("[")+1:i.rfind("]")]
|
|
miniL.append(value)
|
|
#print("value= ",value," addr= ",addr)
|
|
elif "outputValue" in i:
|
|
value = i[i.find("=")+2:]
|
|
miniL.append(value)
|
|
if len(miniL)>=3:
|
|
print(miniL)
|
|
miniL.clear()
|
|
miniL=[]
|
|
scapy.sniff(iface="lo", prn=decode)
|
|
|