tr.sh is a small Bash TCP reachability checker. It scans one or more hosts against one or more ports and reports which connections are open or closed.
It is useful for quick checks when you do not need a full port scanner like nmap.
- Supports IPv4 addresses, hostnames, and localhost.
- Supports comma-separated host lists.
- Supports last-octet IPv4 ranges:
192.168.1.5-10192.168.1.5-192.168.1.10
- Supports comma-separated ports and port ranges:
22,80,4438000-8010
- Uses Bash
/dev/tcpfor TCP connection checks. - Avoids unsafe interpolation of user input into shell code.
- Detects
timeoutorgtimeout. - Supports interactive prompts or command-line options.
- Includes colored output,
--no-color, andNO_COLORsupport. - Includes
--open-onlyfor cleaner output. - Prints a scan summary.
- Bash 4.x or newer.
- Linux, macOS, or another environment where Bash supports
/dev/tcp. timeoutfrom GNU coreutils.
On most Linux systems, timeout is already available.
On macOS, install GNU coreutils:
brew install coreutilsThe script automatically uses gtimeout if timeout is not available.
git clone https://github.com/yourusername/yourrepo.git
cd yourrepo
chmod +x tr.shInteractive mode:
./tr.shCommand-line mode:
./tr.sh --hosts 192.168.1.1,192.168.1.5-10 --ports 22,80,443Short options:
./tr.sh -H localhost,example.com -p 80,443 -t 2Show only open ports:
./tr.sh -H 192.168.1.1-20 -p 22,80,443 --open-onlyDisable colors:
./tr.sh -H example.com -p 80,443 --no-color| Option | Description |
|---|---|
-H, --hosts |
Comma-separated hosts, IPs, or IPv4 ranges. |
-p, --ports |
Comma-separated ports or port ranges. |
-t, --timeout |
Timeout per connection in seconds. Default: 1. |
--open-only |
Print only open results. |
--no-color |
Disable colored output. |
-h, --help |
Show help. |
-v, --version |
Show version. |
Single IPv4 address:
192.168.1.10
Multiple IPv4 addresses:
192.168.1.10,192.168.1.20
Short last-octet range:
192.168.1.5-10
Full last-octet range:
192.168.1.5-192.168.1.10
Hostnames:
localhost,example.com
Single port:
22
Multiple ports:
22,80,443
Port range:
8000-8010
Mixed:
22,80,443,8000-8010
Scanning 2 host(s), 3 port(s), 6 check(s), timeout 1s...
OPEN - localhost:22
CLOSED - localhost:80
CLOSED - localhost:443
OPEN - example.com:80
OPEN - example.com:443
CLOSED - example.com:8080
Summary: 3 open, 3 closed, 6 total
This script checks TCP connectability only. It does not identify services, perform UDP scans, detect operating systems, or replace a full scanner such as nmap.
Use it only on systems and networks you own or have permission to test.
GPL-3.0-or-later. See https://www.gnu.org/licenses/gpl-3.0.html.