James's Ramblings

Testing if a port is open

Created: January 07, 2025

TCP

Netcat

nc -v ADDRESS PORT
  • Works on: Linux and macOS.
  • On Linux, nc is the netcat command.

cURL

curl ADDRESS:PORT
  • Connection refused: port is closed.
  • Connection timed out: port is not reachable.
  • cURL exits immediately if the port is open. May get an “empty reply” if the server does not send any data.

UDP

socat

socat STDIO UDP-CONNECT:ADDRESS:PORT
  • Connection refused: port is closed.
  • No response within a few seconds: port is (likely) not reachable.
  • socat exits immediately if the port is open.