sourceperl / pyModbusTCP

A simple Modbus/TCP library for Python
MIT License
297 stars 104 forks source link

Connect and disconnect events #59

Closed unregistered33 closed 2 months ago

unregistered33 commented 2 years ago

First, big thanks for your work! Is it possible to handle events on connection and disconnection of the client to the server? This is required for access control and logging. Now i have a function which look at client_info.address and compare with access_list file. This function work in MyDataHandler (read_coils and other), but i think its not good practice.

sourceperl commented 10 months ago

If it's still an issue for you, at the pyModbusTCP server level, the only thing you can do is what you do. Create your own DataHandler class and do filtering/logging for each register bank.

But, at TCP level, you can perhaps do the job with an external tool.

Like, for example, with UFW firewall if you are on linux platform :

# add ufw to system
sudo apt install ufw
# turn on firewall (this will deny all incoming connections)
sudo ufw enable
# allow connection from any IPv4 address (with log) to modbus TCP port
sudo ufw allow log-all proto tcp from 0.0.0.0/0 to any port 502