How-Tos

How-To: Test a TCP Port Without Telnet Using nc, Bash, curl and openssl

Leave a comment

With Microsoft deprecating telnet.exe, here’s what I use now when I just need to know “is that port open, and what’s answering?” Swap example.com and the port for your own target. Everything here is read-only.

1. nc (netcat): the quick yes or no

nc -zv -w 3 example.com 443

-z connects without sending data, -v tells you the result, and -w 3 gives up after three seconds. To check a small range: nc -zv -w 2 example.com 20-25.

2. Bash alone, when nc isn’t installed

timeout 3 bash -c '</dev/tcp/example.com/443' && echo open || echo closed

Bash’s built-in /dev/tcp works on almost any Linux box, even minimal containers.

3. curl: is the web service actually healthy?

curl -sv -o /dev/null --connect-timeout 3 https://example.com/ 2>&1 | grep -E "Connected|HTTP/"

An open port isn’t always a working service. This shows the connection and the HTTP status line.

4. openssl s_client: what’s the TLS really saying?

openssl s_client -connect example.com:443 -servername example.com -brief </dev/null

You get the protocol, cipher and certificate subject. For mail servers, add -starttls smtp and use port 587.

5. Talk to a plain-text service by hand

nc example.com 25

This is the old telnet trick: you’ll see the SMTP banner and can type commands. Quit with QUIT or Ctrl+C.

On Windows

Test-NetConnection example.com -Port 443

PowerShell’s built-in replacement. Look for TcpTestSucceeded : True.

Only test hosts you own or are allowed to test. Port-scanning other people’s stuff is how you end up in a conversation you don’t want.

God Bless, and Use the Source!

References & Further Reading

Subscribe (RSS) Follow How-Tos via RSS

Leave a note

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.