Testing Network Connections
  • 31 Mar 2025
  • 1 Minute to read
  • Dark
    Light

Testing Network Connections

  • Dark
    Light

Article summary

Overview

Network testing plays a crucial role in ensuring the reliability, security, and performance of a network infrastructure. Administrators can gain valuable insights into the network's health by reaching out to specific ports on servers or devices. 

This document overviews standard network testing techniques using PowerShell commands, empowering administrators to diagnose issues, verify connectivity, and maintain network integrity.


PowerShell Commands for Port Testing

1. Test-NetConnection

The Test-NetConnection cmdlet allows administrators to check the status of a specific port on a remote server or device. By specifying the server address and port number, this command tests whether the port is open and accessible, providing valuable information for troubleshooting network issues.

Test-NetConnection <server.address> -p <port-number>

2. Looping Through Ports

Administrators can utilize a foreach loop in PowerShell to test a range of ports quickly. This loop iterates through a specified range of port numbers, using Test-NetConnection to check each port's status. This method is helpful in identifying open ports within a range.

foreach ($port in <starting-port>..<ending-port>) {If (($a=Test-NetConnection <server-address> -Port $port -WarningAction SilentlyContinue).tcpTestSucceeded -eq $true){ "$port is open"}}

3. Get-NetFirewallPortFilter

The Get-NetFirewallPortFilter cmdlet allows administrators to inspect firewall rules and port filters in use on a Windows machine. This information is essential for understanding how network traffic is controlled and can aid in diagnosing connectivity issues related to firewall rules.

Get-NetFirewallPortFilter

4. Using netstat

The netstat command and PowerShell's capabilities can help administrators identify which processes are listening on specific ports. This is particularly useful when troubleshooting port conflicts or identifying rogue processes.

netstat -ano | find "<port-number>"

Alternative Command

With "findstr" there are more possibilities for complex search patterns. The "/I" flag is used to make the search case-insensitive. However, its complexity may result in slower speeds.

netstat -ano | find "<port-number>"



Was this article helpful?