What is a simple way in Windows to test if traffic gets through to a specific port on a remote machine?
I found a hiddem gem the other day from Microsoft that is designed for testing ports:
"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. "
Which version of Windows? For Windows 8/Server 2012 and later, the following works in PowerShell:
Test-NetConnection 188.8.131.52 -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
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.
Use the telnet command to connect to the server on the specified port, and see if a connection can be established.
$ telnet my_server 25 220 my_server ESMTP Postfix
$ telnet my_server 23632 Connecting To my_server...Could not open connection to the host, on port 23632: Connect failed
Use netcat Windows port:
>nc -zvv www.google.com 80 www.google.com [184.108.40.206] 80 (http) open sent 0, rcvd 0 > >nc -zvv www.google.com 888 www.google.com [220.127.116.11] 888 (?): TIMEDOUT sent 0, rcvd 0: NOTSOCK >
the following command will list all ports in use on the machine...
The output contains the protocol, local address, foreign address and current state
As @iszi's answer suggested, using the free
nmap utility downloadable from nmap.org is a viable option. It could scan for UDP or TCP ports. Example:
nmap -n -P0 -p "80,443" microsoft.com duolingo.com
-n never do DNS resolution -P0 do not ping to test 'up' state -p this is the list of desired ports "22,80,443" check in SSH, HTTP and HTTPS in TCP
The port list should be inside quotes in Windows because the comma is interpreted as space in the shell.
Nmap scan report for microsoft.com (18.104.22.168) Host is up (0.21s latency). Other addresses for microsoft.com (not scanned): 22.214.171.124 126.96.36.199 188.8.131.52 184.108.40.206 PORT STATE SERVICE 80/tcp open http 443/tcp open https Nmap scan report for duolingo.com (220.127.116.11) Host is up (0.068s latency). PORT STATE SERVICE 80/tcp open http 443/tcp open https Nmap done: 2 IP addresses (2 hosts up) scanned in 0.62 seconds
Port 22 is not open on the tested hosts.