WEBTOOLIST.
STATIC WEB PLATFORM
NO ACCOUNTS / NOTHING TO INSTALL

$ webtoolist --script port-check

Port Reachability Check

Check whether TCP ports on a host are reachable, with a timeout.

category Networking shell Bash 4+ updated 2026-08-14
networktcpportsdiagnostics
Safety notes
  • Connects to the listed ports; only scan hosts you own or are authorised to test.
  • Firewalls may drop packets, so a timeout is not proof the service is down.

Dependencies: bash /dev/tcp

Usage

  • Pass host then one or more ports.
  • Set TIMEOUT (seconds) to change the default 2-second probe.

Script

#!/usr/bin/env bash
set -euo pipefail

host="${1:-}"
shift || true
(($# > 0)) || { echo "usage: $0 HOST PORT [PORT...]" >&2; exit 1; }
timeout_s="${TIMEOUT:-2}"

for port in "$@"; do
  if timeout "$timeout_s" bash -c "</dev/tcp/$host/$port" 2>/dev/null; then
    echo "open    $host:$port"
  else
    echo "closed  $host:$port"
  fi
done

Example

./port-check example.com 22 80 443
TIMEOUT=5 ./port-check 192.168.1.10 5432

Notes

  • Uses Bash’s /dev/tcp, so no nc dependency is required.
  • timeout turns an unanswered SYN into a bounded wait instead of a hang.

Related scripts

HTTP Health Check

Check URLs for expected status codes and response time.

Networking