Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pyModbusTCP-cli

Command line tools built on pyModbusTCP:

Command Role
mbtcp-server Modbus/TCP server (test a client, a SCADA, a gateway...)
mbtcp-client Modbus/TCP client: read and write requests from the command line
mbtcp-tcp2rtu gateway: Modbus/TCP clients -> Modbus/RTU slaves on a serial line
mbtcp-rtu2tcp gateway: a Modbus/RTU master on a serial line -> a Modbus/TCP server

The code of the tools is in the pyModbusTCP library (module pyModbusTCP.tools). This package contains no code: it only adds the commands to the PATH, with pyserial for the gateways. So a plain pip install pyModbusTCP puts no command in the PATH and installs no dependency.

Install

# as isolated command line tools (recommended)
pipx install pyModbusTCP-cli

# or in a virtual environment, with the library
pip install "pyModbusTCP[cli]==0.4.0a3"

Alpha: pyModbusTCP-cli is new with pyModbusTCP 0.4.0, only pre-releases exist for now. The commands, their options and their output may still change before the final release. Without a version or --pre, pip install "pyModbusTCP[cli]" installs the stable pyModbusTCP 0.3.1, without the tools.

Without this package, the tools can still be run from the library alone:

python -m pyModbusTCP.tools server --help
python -m pyModbusTCP.tools client --help
pip install "pyModbusTCP[serial]==0.4.0a3"  # pyserial, only needed by the gateways
python -m pyModbusTCP.tools tcp2rtu --help
python -m pyModbusTCP.tools rtu2tcp --help

Examples

# server on localhost:5020, log the writes of the clients
mbtcp-server --log-changes

# read 4 holding registers from address 0, write some values
mbtcp-client -p 5020 read-holding 0 -n 4
mbtcp-client -p 5020 write-registers 0 100 200 0x1234
mbtcp-client -p 5020 write-read 0 20 22 1 -n 4      # write then read in one request (function 0x17)
mbtcp-client -p 5020 write-coil 10 on
# float32 values on 2 registers, word swapped (CDAB): -T/--type and -b/--byte-order
mbtcp-client -p 5020 write-registers 20 3.14 -2.5 -T float32 -b CDAB
mbtcp-client -p 5020 read-holding 20 -n 2 -T float32 -b CDAB

# TCP clients of the 192.168.1.0/24 network can read (only) the RTU slaves of /dev/ttyUSB0
mbtcp-tcp2rtu -H 0.0.0.0 -A 192.168.1.0/24 --read-only -b 19200 --parity E /dev/ttyUSB0

# an RTU master on /dev/ttyUSB0 reads the Modbus/TCP server 192.168.1.10 (the gateway is the RTU slave 30)
mbtcp-rtu2tcp -a 30 -H 192.168.1.10 /dev/ttyUSB0

On a terminal, mbtcp-client prints a table (registers in hexadecimal, unsigned, signed, binary and ASCII, bits in a grid); with -i it is refreshed in place and the changed values are highlighted. For a script, -f plain, -f csv or -f json (the default output of a pipe is plain: one address value line per item).

Run any command with --help for all its options, -v/--version for its version.

Security

Modbus/TCP has no authentication and no encryption: any host that can reach a server can read and write its data. The server and the TCP to RTU gateway are designed to be safe by default:

  • they listen on localhost and on port 5020 by default: use -H with the address of the network interface that needs it (0.0.0.0 only if every network of the host is trusted);
  • -A/--allow restricts the clients to some IP addresses or networks, --read-only refuses every write;
  • the TCP to RTU gateway only relays the standard data functions by default (no diagnostics, file records or vendor functions): --functions sets the list;
  • the TCP to RTU gateway refuses broadcast requests (unit id 0) unless --allow-broadcast is set (and then only for the write functions, answered at once);
  • --max-connections-per-host (default 16) keeps a single client host from taking every connection, and the TCP to RTU gateway shares the serial line between the client hosts (at most 2 requests per host waiting for the line or in progress).

Port 502 (the standard Modbus/TCP port) is a privileged port on Unix systems. Never run these commands as root (or with sudo) to listen on it. Give the CAP_NET_BIND_SERVICE capability to the Python interpreter of a virtual environment dedicated to the tools instead:

python3 -m venv --copies ~/mbtcp-venv          # --copies: real interpreter files, not links to the system one
~/mbtcp-venv/bin/pip install pyModbusTCP-cli
sudo setcap 'cap_net_bind_service=+ep' ~/mbtcp-venv/bin/python3
~/mbtcp-venv/bin/mbtcp-server -H 192.168.1.10 -p 502

The commands of this virtual environment run its bin/python3, the file with the capability. This does not work with pipx, whose environments use links to the system interpreter (setcap refuses them). See "Listen on the standard Modbus port 502 without root" in the examples README for the details and the precautions.

See also the security policy of pyModbusTCP.

Versions

pyModbusTCP-cli has the version of pyModbusTCP and requires exactly this release of the library (where its code is).

Metadata

Release files for pyModbusTCP-cli 0.4.0a3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyModbusTCP-cli 0.4.0a3
File Size Uploaded Provenance Actions
pymodbustcp_cli-0.4.0a3.tar.gz 4.6 kB Without provenance Details for pymodbustcp_cli-0.4.0a3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyModbusTCP-cli 0.4.0a3
File Interpreter ABI Platform Actions
pymodbustcp_cli-0.4.0a3-py3-none-any.whl Python 3 none any Details for pymodbustcp_cli-0.4.0a3-py3-none-any.whl

Total release size: 9.0 kB

Release files / pymodbustcp_cli-0.4.0a3.tar.gz

Download URL pymodbustcp_cli-0.4.0a3.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ef613d004ada321159e6ef05b85c62bdaf35c47635c1f80e68f4ad1d05f8cace
BLAKE2b-256 checksum
How to use checksums
07e27d4cd07ffc7d6bab007167efa01e6f671736a0b06a21a30220d1a4f86a14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / pymodbustcp_cli-0.4.0a3-py3-none-any.whl

Download URL pymodbustcp_cli-0.4.0a3-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfc83d0210a30d8bd1d70dcf1f03c415c1bac1f40f9ac24fac48f6e25a5ef755
BLAKE2b-256 checksum
How to use checksums
c6b22b06606d7ea89155f486b40e68d551c9776a78a8b5b24aa8a06d3059c617
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for pyModbusTCP-cli 0.4.0a3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page