ser2sock is a lightweight application written in Go to expose a serial device over TCP/IP. It enables bidirectional communication between a serial device and a TCP client, with options for verbose logging and decoding traffic.
- Forward data between a serial port and a TCP connection.
- Configurable serial device, baud rate, and TCP listening address.
- Filter connections by allowed IP addresses.
- Optional verbose logging of incoming and outgoing data.
- Decode data into human-readable text (UTF-8) or display raw hexadecimal.
arch=$(uname -m | sed -e "s/aarch64/arm64/" -e "s/x86_64/amd64/")
wget -O ser2sock.deb https://github.com/tamcore/ser2sock/releases/latest/download/ser2sock_linux_${arch}.deb
dpkg -i ser2sock.deb
arch=$(uname -m | sed -e "s/aarch64/arm64/" -e "s/x86_64/amd64/")
rpm -Uvh https://github.com/tamcore/ser2sock/releases/latest/download/ser2sock_linux_${arch}.rpm
arch=$(uname -m | sed -e "s/aarch64/arm64/" -e "s/x86_64/amd64/")
wget -O ser2sock.apk https://github.com/tamcore/ser2sock/releases/latest/download/ser2sock_linux_${arch}.apk
apk add --allow-untrusted ser2sock.apk
- Go version 1.16 or later installed on your system.
- Clone
git clone https://github.com/tamcore/ser2sock.git cd ser2sock
- Build
go build -o ser2sock
./ser2sock -device <serial_device> -listen <address:port> -baud <baud_rate> [options]
Option | Description | Example |
---|---|---|
-device |
Path to the serial device. Required. | /dev/ttyUSB0 , COM3 , /dev/zigbee1 |
-listen |
TCP address and port to listen on. | 0.0.0.0:5000 |
-baud |
Baud rate for the serial device. Default: 9600 . |
115200 |
-allowed |
Comma-separated list of allowed client IPs. Leave empty to allow all IPs. | 192.168.1.100,192.168.1.101 |
-verbose |
Enable verbose logging for incoming and outgoing data. (no value, just add the flag) | |
-decode |
Attempt to decode data into human-readable UTF-8 text. Defaults to raw hexadecimal format. (no value, just add the flag) |
Expose the serial device /dev/ttyUSB0
on TCP port 5000
with a baud rate of 9600
:
./ser2sock -device /dev/ttyUSB0 -listen 0.0.0.0:5000 -baud 9600
Allow only clients from specific IPs:
./ser2sock -device /dev/ttyUSB0 -listen 0.0.0.0:5000 -baud 9600 -allowed "192.168.1.100,192.168.1.101"
Enable detailed logging of IN/OUT traffic:
./ser2sock -device /dev/ttyUSB0 -listen 0.0.0.0:5000 -baud 9600 -verbose
Attempt to decode data into human-readable text when possible:
./ser2sock -device /dev/ttyUSB0 -listen 0.0.0.0:5000 -baud 9600 -verbose -decode
Accepted connection from 192.168.1.100:54832
IN (TCP->Serial): 48656c6c6f
OUT (Serial->TCP): fe00
Accepted connection from 192.168.1.100:54832
IN (TCP->Serial): "Hello"
OUT (Serial->TCP): (binary: fe00)
- go-serial: For interacting with the serial device.
go get ./...
Run the application locally and connect using a TCP client like telnet or netcat:
telnet <server_ip> <port>