Check if a port is open or closed

The Problem

You want to run a simple command to check if a port is open on a remote host. This is great because it doesn’t require an application to do such a simple task!

    The Fix

    Open PowerShell

    PS C:\ Test-NetConnection -ComputerName www.google.com -Port 80

    Result:

    ComputerName : www.google.com
    RemoteAddress : 172.217.167.68
    RemotePort : 80
    InterfaceAlias : Ethernet
    SourceAddress : 192.168.20.116
    TcpTestSucceeded : True

     

    If you want some more information about the request, just append -InformationLevel “Detailed” to the above command.

    PS C:\ Test-NetConnection -ComputerName www.google.com -Port 80 -InformationLevel “Detailed”

    Result:

    ComputerName : www.google.com
    RemoteAddress : 172.217.167.68
    RemotePort : 80
    NameResolutionResults : 172.217.167.68
    MatchingIPsecRules :
    NetworkIsolationContext : Internet
    InterfaceAlias : Ethernet
    SourceAddress : 192.168.20.116
    NetRoute (NextHop) : 192.168.20.254
    TcpTestSucceeded : True

     

    Want to know what other parameters you can use? Check out the Microsoft docs page here!