This page looks best with JavaScript enabled

PowerShell - Check if remote port is open

 ·   ·  ☕ 1 min read

There are tons of ways to check if the port is open on a remote server. I think I found the fastest one, which is a Powershell one-liner:

1
(new-object Net.Sockets.TcpClient).Connect($host, $port)

For testing purposes you can use the following command:

1
(new-object Net.Sockets.TcpClient).Connect("google.com", 80)

It should give you no results. This means connection succeeded.

In real life you may encounter the following two outputs in red:

(1) Exception calling “Connect” with “2” argument(s): “A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xxx.xxx.xxx.xxx:xx”

or

(2) Exception calling “Connect” with “2” argument(s): “No connection could be made because the target machine actively refused it xxx.xxx.xxx.xxx:xx”

It depends on the endpoint firewall configuration. For the server, which receives too many connection requests, it is more natural to drop connections (1) rather than refuse them (2).


Victor Zakharov
WRITTEN BY
Victor Zakharov
Web Developer (Angular/.NET)