s7commctl
s7commctl is a command-line S7comm client for ISO-on-TCP (TCP port 102), built on go-s7comm. It is meant for commissioning, troubleshooting and engineering work on PLCs you are responsible for. This page follows s7commctl v0.5.0, built on go-s7comm v0.12.0.
Install
Section titled “Install”curl -fsSL https://get.otfabric.io/s7commctl | shirm https://get.otfabric.io/s7commctl.ps1 | iexcurl -fsSL https://get.otfabric.io/s7commctl | env OTF_UNMANAGED_INSTALL=/usr/local/bin shBinaries for Linux (x86-64, ARM64, ARMv7), macOS (Intel, Apple silicon) and Windows (x86-64, ARM64). The installer checks the release's SHA-256 checksum, installs per user without sudo (~/.local/bin, on Windows %LOCALAPPDATA%\OTFabric\bin) and upgrades in place when you run it again. Pin a version with OTF_VERSION; the CI line installs into a fixed directory without touching PATH or shell profiles. All installer options, release archives for offline machines. To build from source instead: make build in a checkout. Check the install with s7commctl version.
Connecting
Section titled “Connecting”Every command that talks to a PLC takes --ip, and --port when the PLC is not on the default port 102. Pick the CPU with --rack and --slot. s7commctl also supports automatic rack/slot selection and explicit local and remote TSAPs; the JSON output records which of the three connection modes (rack_slot, auto_rack_slot or explicit_tsap) a command used.
Most flags can also come from S7COMMCTL_* environment variables, for example S7COMMCTL_IP, S7COMMCTL_PORT, S7COMMCTL_RACK, S7COMMCTL_SLOT, S7COMMCTL_TIMEOUT, S7COMMCTL_AUTO_RACK_SLOT, S7COMMCTL_LOCAL_TSAP and S7COMMCTL_REMOTE_TSAP:
export S7COMMCTL_IP=192.168.1.10export S7COMMCTL_RACK=0export S7COMMCTL_SLOT=1s7commctl identifys7commctl warns when the target address looks publicly routable. --no-exposure-warning (or S7COMMCTL_NO_EXPOSURE_WARNING) turns the warning off in environments where that is expected.
Command tree
Section titled “Command tree”s7commctl├── discover find S7 endpoints in a CIDR range├── identify SZL-based device metadata├── read read an area (DB, I, Q, M, T, C, ...)├── write write an area (requires --dangerous)├── blocks alias for list blocks├── list│ ├── blocks│ ├── db│ └── areas├── block│ ├── info│ └── upload├── diagnostic CPU state, protection level, diagnostic buffer├── fingerprint PDU size, AMQ, TSAP behaviour, CPU generation heuristic├── probe│ └── rackslot which rack/slot pairs are accepted or confirmed├── scan│ └── read-ranges which byte ranges of an area are readable├── compare│ └── read same read across several rack/slot pairs├── profile capability summary in one run├── record periodic reads to a file├── sniff decode TPKT streams arriving on a local socket├── pcap-decode offline decode of a pcap capture├── replay scripted replay endpoint for tests├── completion└── versionA safe first session
Section titled “A safe first session”When you meet an unfamiliar endpoint, start with read-only steps and widen only as needed.
-
Find the rack and slot. Setup acceptance alone is weak evidence, so ask for a follow-up query too:
Terminal window s7commctl probe rackslot --ip 192.168.1.10 --strict --first-confirmed--confirm szl,--confirm cpu-stateor--confirm anypicks the confirming query.--summary-onlyprints counts and one recommended connection tuple. The command exits 0 when it finds at least one valid pair and 1 when it finds none. -
Identify the device:
Terminal window s7commctl identify --ip 192.168.1.10 --rack 0 --slot 1 --format jsonSince v0.5.0 the fields come from SZL 0x0011 and 0x001C by record index:
module_nameis the module’s name (such asPLC_1),cpu_typeits module type (such asCPU 315-2 PN/DP) andfw_versionreadsVx.y.z;module_type,system_name,plant_id,copyrightandmemory_card_serialwere added (a string or null in JSON). Before v0.5.0,identify,fingerprint,diagnostic,profileand the block commands sent requests a real S7-300 or S7-400 could not answer correctly and decoded answers at wrong offsets, so values recorded with an older version differ. -
Get a capability summary (setup, rack/slot, identity and block list) in one run:
Terminal window s7commctl profile --ip 192.168.1.10 -
Make small, bounded reads:
Terminal window s7commctl read --ip 192.168.1.10 --area DB --db 1 --offset 0 --size 16 --format hex -
Map which parts of an area respond:
Terminal window s7commctl scan read-ranges --ip 192.168.1.10 --area DB --db 1 --start 0 --end 1024 --probe-size 32
If many rack/slot pairs behave the same, compare read shows whether the endpoint is rack/slot-insensitive (a gateway or a compatibility layer, for example):
s7commctl compare read --ip 192.168.1.10 --area DB --db 1 --offset 0 --size 32 --candidates 0/0,0/1,0/2Reading
Section titled “Reading”read supports DB, I, Q, M, T and C, plus the extended areas DATA_RECORD, S7200AO, IEC_COUNTER_200 and IEC_TIMER_200. --type decodes the bytes as BOOL, INT, DINT, REAL or STRING:
s7commctl read --ip 192.168.1.10 --area M --offset 100 --size 8 --type int --format jsonThe output always shows the read status (success, short-read, empty-read, rejected and so on) and the requested and returned lengths. With --format json, a decoded array holds the typed values. Add --strict-read to make the command fail when the status is not success.
To sample a value over time, record writes one line per read:
s7commctl record --ip 192.168.1.10 --area DB --db 1 --offset 0 --size 8 \ --every-ms 1000 --count 60 --output samples.jsonlThe output file is created with mode 0600, because a recording holds process values.
Writing
Section titled “Writing”The safety model has three rules:
- Reads are always allowed.
writerefuses to run without--dangerous.- With
--dangerous, s7commctl asks for confirmation unless you also pass--force.
# Interactive: asks before writings7commctl write --ip 192.168.1.10 --area DB --db 1 --offset 0 --type int --value 123 --dangerousUse --force only in automation where nobody can answer the prompt.
Blocks and diagnostics
Section titled “Blocks and diagnostics”s7commctl list blocks --ip 192.168.1.10 --format tables7commctl list db --ip 192.168.1.10 --format jsons7commctl block info --ip 192.168.1.10 --type DB --number 1 --format jsons7commctl block upload --ip 192.168.1.10 --type DB --number 1 --format jsons7commctl diagnostic --ip 192.168.1.10 --format tables7commctl fingerprint --ip 192.168.1.10 --format jsonBlock upload copies a block from the PLC to your machine. It does not change the PLC. Whether it is allowed depends on the CPU and its protection level. diagnostic shows the CPU state, the protection level and the diagnostic buffer, which are often more restricted than plain reads.
Offline and test tools
Section titled “Offline and test tools”pcap-decode --file capture.pcap --port 102decodes S7 frames from a packet capture on a best-effort basis. It does not reassemble TCP streams.sniff --listen :15102accepts one TCP connection on a local port and decodes the TPKT frames it receives.replay --listen :1102 --script replay.hexanswers one client with scripted response frames, one hex TPKT frame per line. It is a scaffold for deterministic tests, not a PLC simulator. For a full test server, use snap7-interop.
Output formats
Section titled “Output formats”--format takes table (human readable), json, quiet and hex. --quiet is the same as --format quiet. For discover it prints one IP address per line.
Single-target commands share one JSON envelope:
{ "target": { "ip": "192.168.1.10", "port": 102 }, "request": { "connection_mode": "rack_slot", "rack": 0, "slot": 1 }, "result": {}}On failure, an error object with code and message replaces result. discover returns a plain array with one object per device, and list blocks returns an array of blocks.
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Findings: the operation completed and reports a non-success (probe found no valid rack/slot, a short read with --strict-read) |
| 2 | Usage: invalid flags or input, an address go-s7comm refuses before sending (a negative offset, a DB above 65535, a range past the S7ANY address limit), a write without --dangerous or aborted at the prompt |
| 3 | A request larger than the negotiated PDU |
| 4 | Transport: connecting failed, the connection was lost, a listener cannot start |
| 5 | Timeout |
| 6 | Protocol: the PLC refused the request, or a malformed response |
| 9 | Permission: the operating system refused, for example binding port 102 |
| 10 | An output file could not be opened or written |
| 130 | Interrupted by SIGINT or SIGTERM before a result; a record stopped this way ends with 0 |
The codes follow the OT Fabric CLI exit-code table since v0.3.0. S7COMMCTL_FORMAT (or S7COMMCTL_OUTPUT_FORMAT) sets the default of --format. Since v0.4.0 an address the S7ANY format cannot carry is refused before anything is sent: before, write --db 65537 wrote to DB 1.
Shell completion
Section titled “Shell completion”source <(s7commctl completion bash)source <(s7commctl completion zsh)s7commctl completion fish | sourceEnum flags such as --area, --format, --type and --confirm complete with their allowed values.