In Windows, using the command line, how do you check if a remote port is open?

Solution 1:

Which version of Windows? For Windows 8/Server 2012 and later, the following works in PowerShell:

Test-NetConnection 128.159.1.1 -Port 80

Some Googling will also turn up alternatives which use the .NET Framework directly (since PowerShell lets you do that) for systems running lower versions of Windows that won't have Test-NetConnection available.

If you're not averse to using third-party utilities, Nmap is also a very good friend to have and it works from the command line.

Solution 2:

I found a hiddem gem the other day from Microsoft that is designed for testing ports:

Portqry.exe

"Portqry.exe is a command-line utility that you can use to help troubleshoot TCP/IP connectivity issues. Portqry.exe runs on Windows 2000-based computers, on Windows XP-based computers, and on Windows Server 2003-based computers. The utility reports the port status of TCP and UDP ports on a computer that you select. "


Solution 3:

Use the telnet command to connect to the server on the specified port, and see if a connection can be established.

Success:

$ telnet my_server 25
220 my_server ESMTP Postfix

Fail:

$ telnet my_server 23632
Connecting To my_server...Could not open connection to the host, on port 23632:
Connect failed

Solution 4:

Telnet will work for TCP.

Netcat is a better tool for these sorts of things, including UDP, watch out though, some AV softwares consider it an 'evil hacker tool'