139

What is a simple way in Windows to test if traffic gets through to a specific port on a remote machine?

Matt
  • 1,571
  • 4
  • 15
  • 16

8 Answers8

142

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.

Iszi
  • 2,376
  • 8
  • 25
  • 33
83

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. "

Steve Bennett
  • 5,750
  • 12
  • 47
  • 59
Peter M
  • 1,036
  • 9
  • 20
  • 1
    Note: Attempting to download this from Microsoft returned a page stating the download is "no longer available". – dgw Sep 16 '17 at 00:36
  • @dgw Thanks for that .. google shows a new version if you search for `portray" that I'll check out tomorrow – Peter M Sep 16 '17 at 02:27
  • 4
    console version http://www.microsoft.com/downloads/details.aspx?familyid=89811747-c74b-4638-a2d5-ac828bdc6983&displaylang=en and ui version: http://download.microsoft.com/download/3/f/4/3f4c6a54-65f0-4164-bdec-a3411ba24d3a/portqryui.exe Ref: https://support.microsoft.com/en-us/help/310099/description-of-the-portqry-exe-command-line-utility – Junior Mayhé Apr 13 '18 at 19:16
28

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
Jørn Schou-Rode
  • 720
  • 1
  • 6
  • 12
  • 17
    doesn't work for UDP. – Adriano Varoli Piazza Jul 02 '09 at 20:23
  • 9
    UDP is connectionless.. – Alkanshel Jun 23 '14 at 18:46
  • Yes telnet uses TCP not UDP. Yes UDP is "connectionless" but PING (Datagram Sockets) also. So if the UDP port to test can give feedback... As far I remember "connectionless" in TCP/IP does not mean unidirectional but that connection is "not secure" in terms like you might get double answers-packets or not in the right order. – grenix Jun 10 '21 at 07:31
  • Telnet has not been available on recent versions of Windows for years - it's now Oct 2022. – DAB Oct 28 '22 at 12:55
8

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'

whatsisname
  • 291
  • 1
  • 3
  • 8
2

Use netcat Windows port:

>nc -zvv www.google.com 80
www.google.com [108.177.96.103] 80 (http) open
sent 0, rcvd 0
>

>nc -zvv www.google.com 888
www.google.com [108.177.96.147] 888 (?): TIMEDOUT
sent 0, rcvd 0: NOTSOCK
>
rustyx
  • 1,676
  • 3
  • 21
  • 30
1

the following command will list all ports in use on the machine...

netstat -a

The output contains the protocol, local address, foreign address and current state

Netstat documentation on microsoft.com

Baldy
  • 195
  • 2
  • 11
0

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

where

-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.

Result:

Nmap scan report for microsoft.com (20.53.203.50)
Host is up (0.21s latency).
Other addresses for microsoft.com (not scanned): 20.81.111.85 20.103.85.33 20.84.181.62 20.112.52.29

PORT    STATE SERVICE
80/tcp  open  http
443/tcp open  https

Nmap scan report for duolingo.com (184.72.124.184)
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.

Reference: https://nmap.org/book/man.html

Fjor
  • 196
  • 5
-2

'netstat' is you friend.

quosoo
  • 105
  • 1
  • 3
    Local machine yes, remote machine no. –  Jul 02 '09 at 18:04
  • 4
    This answer was posted before the edit that specified that it's about a port on remote machine. –  Jul 02 '09 at 18:11