Wednesday, August 7, 2013

Checking if a TCP Port is Open on a Remote Server using Powershell

This tip is related to a previous post about using a utility called TCPing.exe to check to see if a remote port is open (i.e. the service is listening and accepting connections).  Since Windows 2008 doesn't come with the telnet client installed and since some circumstances will mean that access to the internet isn't available (i.e. a server in a hardened data center), an alternative method is to use Powershell.

This can be wrapped into a script pretty easily, or if you just memorize it, you can impress whomever is looking over your shoulder.

So, memorize this bit (this will ping

If the output is "True", then then the tcping was successful.  If the connection is unsuccessful, it will be completely obvious in the output.

To wrap it into a script, create a text file like this (this will ping by default. Pass the server name and port to override the default.