Powershell

How to Find Listening Ports with Netstat and PowerShell

Listening ports on the system talk about the processes and services that are waiting for the service network requests. These services or requests either listen on a UDP or a TCP port. Moreover, listening ports on PowerShell can normally be found using the “netstat” cmdlet. Alternatively, the cmdlet “Get-NetTCPConnection” is also be used for this purpose.

This article will get the listening ports on the system using PowerShell.

How to Find Listening Ports With “netstat” Cmdlet and PowerShell

These are the commands that can be utilized to find the listening ports in PowerShell:

Method 1: Use the “netstat” Cmdlet in PowerShell to Get the Listening Ports

The “netstat” cmdlet is a PowerShell utility used to display the active TCP (Transmission Control Protocol). It can get the list of listening ports with the aid of specific parameters in PowerShell.

Example
This illustration will output the listening ports in PowerShell using the “netstat” cmdlet:

netstat -an | Select-String "Listening"

In accordance with the above code:

  • First, specify the “netstat” cmdlet along with the “-an” parameter.
  • Then, add the pipeline “|” to transfer the output of the previous command to the next command.
  • After that, specify the “Select-String” cmdlet and assign the value “Listening” to it:

Method 2: Use the “netstat” Alternative “Get-NetTCPConnection” Cmdlet to Find the Listening Ports in PowerShell

The alternative of the “netstat” to get the list of listening ports in PowerShell is the “Get-NetTCPConnection” cmdlet. Generally, it can get the list of TCP connections, but with the use of some specific parameters, it can also get the listening ports in PowerShell.

Example
This instance will get all the listening ports on the computer using the “Get-NetTCPConnection” command in PowerShell:

Get-NetTCPConnection -State Listen

According to the above code:

  • First, specify the “Get-NetTCPConnection” cmdlet, then add the “-State” parameter and assign it the “Listen” value:

It can be observed that all of the listening ports has been fetched successfully.

Conclusion

The “netstat” cmdlet in PowerShell is used to get the list of listening ports on the system. For that reason, first, specify the “netstat” cmdlet along with the “-an” parameter. Then, add the pipeline “|”. After that, specify the “Select-String” cmdlet, and assign the value “Listening” to it. This blog has discussed various methods to get the list of listening ports on the system using PowerShell.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.