brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Test-NetConnection checks whether a TCP port answers, without telnet

Network and access
~/tips/tip-windows-test-netconnection-port

Test-NetConnection -ComputerName example.com -Port 443

Tests from PowerShell whether a remote TCP port accepts connections, and shows the ping result as well.

The classic answer to “is that port open?” used to be installing telnet. PowerShell has a built-in check.

Test-NetConnection -ComputerName example.com -Port 443
Test-NetConnection example.com -Port 443 -InformationLevel Quiet

The result shows the name resolution, the ping reply and then TcpTestSucceeded, which is True when the connection to that port worked. With -InformationLevel Quiet you only get True or False, which suits scripts.

-CommonTCPPort accepts a few service names instead of a number, such as HTTP, RDP, SMB and WINRM, so -CommonTCPPort RDP tests port 3389.

I find it useful when something works from one network and not from another, because you can run the same command on both and compare the answers.

The caveat is that the cmdlet always runs a ping test and name resolution too, even when you only care about the port. A PingSucceeded of False does not mean the TCP test failed, since many hosts block ping. Read TcpTestSucceeded for the port. A False there can mean nothing is listening, or a firewall or the network blocks it, and the cmdlet cannot tell you which.

Further reading: Microsoft Learn: Test-NetConnection

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link