Skip to content

iec104ctl

iec104ctl is a command-line tool for IEC 60870-5-104 in both roles. As a controlling station it interrogates an RTU, gateway or IED, watches its events, issues commands and set points (direct or select-before-operate), synchronizes its clock and transfers files, over TCP, TLS or the application-layer security of IEC 62351-5. As a controlled station it simulates an RTU from a YAML model. It is one of the four tools of iec60870ctl, next to iec101ctl, iec102ctl and iec103ctl, and is built on go-iec60870-5. This page describes v0.9.1, built on go-iec60870-5 v0.5.1.

Terminal window
curl -fsSL https://get.otfabric.io/iec104ctl | sh

Binaries 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. Check the install with iec104ctl version.

  1. Start the built-in demo station in one terminal:

    Terminal window
    iec104ctl server start
  2. Interrogate it from another:

    Terminal window
    iec104ctl client interrogate --ip 127.0.0.1 --ca 1
  3. Watch its events until Ctrl-C:

    Terminal window
    iec104ctl client monitor --ip 127.0.0.1 --interrogate

Every client command takes the station as a URL, or as an address and port. The two styles are mutually exclusive.

Flags Connects to
--url tcp://host[:port] IEC 104 over TCP; port 2404 when omitted
--url tls://host[:port] IEC 104 over TLS (IEC 62351-3); port 19998 when omitted
--ip host [--port n] TCP on port 2404 or n; TLS when a --tls... flag is given

--ca is the common address (default 1). --timeout bounds connecting and each request, in milliseconds (default 10000). --originator sets the originator address.

TLS flag Meaning
--tls Use TLS with --ip
--tls-ca PEM file with the CA certificates to verify the station; system roots by default
--tls-cert, --tls-key Client certificate and key, for mutual authentication
--tls-server-name Name to verify the certificate against
--tls-insecure Do not verify the station’s certificate. Test setups only
Terminal window
iec104ctl client interrogate --url tls://rtu.example.net --tls-ca ca.pem --tls-cert scada.pem --tls-key scada.key

--secure runs the A-Profile of IEC 62351-5, as IEC TS 60870-5-7 applies it to IEC 104. After STARTDT the client and the station agree on keys in a Station Association authenticated with their certificates, then on session keys. From then on every ASDU travels as Secure Data (S_SD_NA_1), authenticated with an HMAC, or encrypted and authenticated with AES-256-GCM, and numbered against replay. The command starts only once the session is secure. It works over TCP and over TLS.

Flag Meaning
--secure Run the A-Profile. The other flags of this table need it, and it needs the next three
--security-cert PEM file with the own station certificate: P-256, or X25519 signed by an authority
--security-key PEM file with its private key
--security-trust PEM file with the stations to trust. A CA certificate is an authority: every station certificate it signed is accepted. Any other certificate is pinned: that station’s self-signed certificate is accepted
--association-id The AIM, this controlling station’s half of the association ID, 1-65535 (default 1)
--mal MAC algorithm: hmac-sha-256 (default), hmac-sha-256/8, hmac-sha3-256, hmac-sha3-256/8, by name or code
--dpa Data protection: a MAC algorithm as for --mal, or aes-256-gcm to encrypt as well (default: --mal)

With a plant authority that signs both certificates, each side trusts the authority alone:

Terminal window
iec104ctl server start --secure --security-cert station.pem --security-key station.key --security-trust ca.pem --roles viewer
iec104ctl client interrogate --ip 127.0.0.1 --secure --security-cert scada.pem --security-key scada.key --security-trust ca.pem --dpa aes-256-gcm

The README has the openssl commands for pinned self-signed certificates and for a plant authority. A refused certificate, an algorithm the station does not accept, or no answer to the key management ends the command with exit code 4 and the error code security_failed, before anything else is sent. A request the station’s roles do not permit is refused with cause 17 (not-authorized), exit code 6. A client without --secure gets no answer from a secure station (exit code 5). --debug traces the security events (STAS_PROC_SUCC, NODE_NOT_AUTR, …) and the algorithms of the session with the frames.

Protocol parameters default to the standard: --k 12, --w 8, --t0 30, --t1 15, --t2 10, --t3 20 (seconds); --k and --w each take 1 to 32767, and --w may exceed --k. A station behind an IEC 60870-5-101 gateway may use shorter address fields: --cot-size (1 or 2), --ca-size (1 or 2) and --ioa-size (1 to 3). If every value looks scrambled, or the station closes the connection on the first request, check these first. --timezone (utc, local or an IANA name such as Europe/Brussels) says which zone the station keeps its clock in.

iec104ctl
├── client
│ ├── interrogate General or group interrogation (C_IC_NA_1)
│ ├── counters Counter interrogation (C_CI_NA_1)
│ ├── read Read information objects (C_RD_NA_1)
│ ├── monitor Print every value the station sends, until interrupted
│ ├── command Process command: single, double, step, set point, bitstring
│ ├── clock Clock synchronization (C_CS_NA_1)
│ ├── reset Reset process command (C_RP_NA_1)
│ ├── ping Test frames (TESTFR) or test commands (C_TS_TA_1)
│ ├── scan Find the stations (common addresses) behind a connection
│ ├── file
│ │ ├── list List the file directory
│ │ ├── get Fetch a file
│ │ └── put Deliver a file
│ └── types List the ASDU type identifications
├── server
│ ├── start Serve a simulated station from a model (or the built-in demo)
│ └── generate-config Write an example station model
├── discover Find IEC 60870-5-104 stations on subnets
├── completion Generate shell completion script
└── version Print version

Start here. These ask, they do not change the station. They still connect and start data transfer, so your connection may take the station’s events while it is open.

Terminal window
# General interrogation, then group 3 only, then filtered
iec104ctl client interrogate --ip 192.168.1.10 --ca 1
iec104ctl client interrogate --ip 192.168.1.10 --group 3
iec104ctl client interrogate --ip 192.168.1.10 --type M_SP_NA_1,M_ME_NC_1 --ioa 100-1999
# Counters (integrated totals are not part of an interrogation)
iec104ctl client counters --ip 192.168.1.10
# Read single objects (one C_RD_NA_1 per address)
iec104ctl client read --ip 192.168.1.10 --ioa 100,1000-1003 --format table
# Stream events, starting with a general interrogation
iec104ctl client monitor --ip 192.168.1.10 --interrogate
# Link test with round-trip times
iec104ctl client ping --ip 192.168.1.10

--type and --ioa filter what is shown; the station is always asked for everything. In monitor, the first column is when a value arrived and the time after @ is the station’s time tag:

2026-10-10T09:15:17.676Z M_DP_TB_1 ca=1 ioa=200 off [good] return-remote @ 2026-10-10T09:15:17.666Z
2026-10-10T09:15:19.286Z M_ME_TF_1 ca=1 ioa=1000 230.20906 [good] spontaneous @ 2026-10-10T09:15:19.285Z

client ping --method testfr (default) sends the link test frame and changes nothing; --method command sends C_TS_TA_1. Add the global --debug flag to any command to trace every frame, decoded and in hex, on stderr.

Terminal window
iec104ctl discover --subnets 192.168.1.0/24
iec104ctl client scan --ip 192.168.1.10
iec104ctl client scan --ip 192.168.1.10 --method sweep --start 1 --end 50 --timeout 1000

discover opens a TCP connection to each address and sends one test frame; it does not start data transfer. More than 4096 hosts need --force-large-scan. client scan finds the common addresses behind one connection, by one interrogation to the broadcast address or by a sweep; either makes every station found send its whole process image.

Terminal window
# Single command, direct execute
iec104ctl client command --ip 192.168.1.10 --type single --ioa 5000 --value on
# Double command with select-before-operate and a short pulse
iec104ctl client command --ip 192.168.1.10 --type double --ioa 5001 --value off --mode sbo --qualifier short
# Floating point set point
iec104ctl client command --ip 192.168.1.10 --type setpoint-float --ioa 5003 --value 231.5
# With a time tag (C_SC_TA_1), waiting up to 5 s for the activation termination
iec104ctl client command --ip 192.168.1.10 --type single --ioa 5000 --value on --time-tag --wait-termination 5000
--type Type identification --value
single C_SC_NA_1 on, off
double C_DC_NA_1 on, off
step C_RC_NA_1 higher, lower
setpoint-normalized C_SE_NA_1 -1 … < 1
setpoint-scaled C_SE_NB_1 -32768 … 32767
setpoint-float C_SE_NC_1 any number
bitstring C_BO_NA_1 0 … 4294967295, or 0x hex
--mode Procedure
execute Direct execute (default)
sbo Select, and when the station has confirmed it, execute
select Select only, to see whether the station accepts it
cancel Select, then deactivate the selection

A selection belongs to the connection that made it and ends with it, so select and cancel operate nothing. --qualifier is none, short, long or persistent for switching commands, or the QL number 0-127 for set points. Parameter commands (P_ME_..., P_AC_NA_1) are not offered.

The safety model:

  • Everything is validated before anything is sent. A rejected invocation exits 3 and has sent nothing.
  • A command is sent exactly once. It is never repeated, also not when its confirmation does not arrive (exit 5).
  • A refusal by the station exits 6, and the message says which step was refused.
  • client reset has no default for --qualifier (process or events).
  • client clock --time refuses a time outside the years 1970 to 2069 (in the --timezone zone) with exit 3, because a time tag carries a two-digit year.
  • client counters --freeze freeze|freeze-reset|reset returns at the station’s confirmation and lists no values; read the frozen values with a following client counters.
  • There is no dry-run flag; the simulated station is the place to rehearse.
Terminal window
iec104ctl client clock --ip 192.168.1.10 --timezone Europe/Brussels
iec104ctl client counters --ip 192.168.1.10 --freeze freeze
iec104ctl client file get --ip 192.168.1.10 --ioa 30000 --name 1 --output record.bin

--format text (default), json or table controls only the result on stdout. Progress, connection state, summaries and the debug trace go to stderr. Streams (client monitor, client ping, server start) write JSON Lines. The JSON field names are a stable contract (ca, ioa, type, type_id, cause, cot, value, quality, timestamp). On failure with --format json a single object {"error": {"kind", "code", "message"}} is written to stdout.

Code Meaning
0 Success
2 Usage: unknown command or flag, missing required flag
3 Invalid input: nothing was sent
4 Transport: cannot connect, connection lost, TLS failure, IEC 62351-5 session not established (security_failed)
5 Timeout: no answer, or no acknowledgement within t1
6 The station refused the request (including cause 17 under IEC 62351-5), or a protocol error
7 Partial success: a valid result that holds failures (a refused address in read, a failed test in ping)
10 Output or internal error
130 Interrupted by Ctrl-C or SIGTERM before a result

The codes follow the OT Fabric CLI exit-code table shared by every *ctl tool. IEC104CTL_FORMAT sets the default of --format (IEC104CTL_OUTPUT_FORMAT is still accepted). Files iec104ctl writes (client file get --output, server generate-config --output and the uploads the station stores) are readable by their owner only (mode 0600).

Every flag has an IEC104CTL_* variable; a flag on the command line wins. Required flags (--ioa of client read, --type and --value of client command, --qualifier of client reset) must still be given on the command line, and --debug has no variable.

Terminal window
export IEC104CTL_URL=tcp://192.168.1.10:2404
export IEC104CTL_CA=1
iec104ctl client interrogate
iec104ctl client read --ioa 1000

server start serves a controlled station from a YAML or JSON model, or the built-in demo.

Terminal window
iec104ctl server generate-config --output station.yaml
iec104ctl server start --config station.yaml --listen 127.0.0.1 --port 12404 --format json
station:
name: Demo bay
common_address: 1
cyclic_interval: 30s
points:
- {ioa: 100, type: M_SP_NA_1, name: Circuit breaker closed, value: true, group: 1}
- ioa: 1000
type: M_ME_NC_1
name: Voltage L1 (kV)
value: 230.4
simulate: {mode: sine, interval: 2s, min: 228, max: 232}
- {ioa: 2000, type: M_IT_NA_1, name: Energy counter (kWh), value: 123456}
commands:
- {ioa: 5000, type: C_SC_NA_1, name: Circuit breaker, target: 100}
- {ioa: 5001, type: C_DC_NA_1, name: Disconnector, target: 200, select_required: true}
files:
- {ioa: 30000, name: 1, size: 4096}
uploads:
accept: true
max_files: 64 # the defaults
max_file_size: 1048576
max_total_size: 16777216

The station answers general, group and counter interrogations, read, clock synchronization, the test command and the reset process command. It executes commands on their target point, direct or select-before-operate (select_required, select_timeout default 30 s), and reports the change with cause 11. Values with simulate change by themselves (toggle, ramp, sine, random, count). State changes are queued until a controlling station acknowledges them; measured values are not kept. It serves any number of connections, and queued events go to the one that started data transfer last. It serves one common address per instance. With uploads.accept the station keeps at most 64 delivered files of up to 1 MiB each and 16 MiB in total by default (since v0.6.0); a delivery beyond a limit is refused when it is announced, and a file delivered to an address that already holds one replaces it.

With --secure and the certificate, key and trust flags, every controlling station must associate with a certificate --security-trust accepts, and each one (each AIM) gets its own association; --association-id is the station’s AIS. --roles viewer,operator,... gives every controlling station those roles of IEC TS 60870-5-7 (viewer, operator, engineer, installer, secadm, secaud, rbacmnt), and a request no role permits is refused with cause 17. The station logs secured when a controlling station has associated, security-refused when an association is refused, and refused for a request its roles do not permit.

Terminal window
# Controlling stations may look, not operate
iec104ctl server start --config station.yaml --secure --security-cert station.pem --security-key station.key --security-trust ca.pem --roles viewer
  • IEC 62351-5 associations are kept in memory: every run of iec104ctl associates anew, and the simulated station forgets its associations when it stops.
  • The simulated station gives every controlling station the same trust and roles. The timers and key usage limits of IEC 62351-5 are the library’s defaults and have no flags.
  • secp256k1, Curve448, brainpoolP256r1 and BLAKE2s are not supported. IEC 62351-5 is tested for interoperability with cB-Sigma/iec60870, not for conformance.
  • No serial link layer: IEC 60870-5-101 is not spoken, only its field sizes over IEC 104.
  • The simulated station serves one common address per instance.
  • No parameter commands in client command.