Open Ports tool icon

Open Ports

Check open ports on your PC — see what is listening and spot anything unexpected.

Platforms
Windows, Linux, macOS
Needs
Nothing to install. PowerShell is built into Windows; the bash version uses the shell's own /dev/tcp support.
Files
Test-OpenPorts.ps1 (PowerShell) · port-scan.sh (bash)
Licence
MIT — read, modify, redistribute
Verified
Ran on our test machine on 2026-10-17
Last reviewed
2026-10-17
Download Test-OpenPorts.ps1Download port-scan.shRead the sourceSee the full workflow

The problem it solves

You installed a service and want to confirm it is reachable, or something feels off and you want a quick sanity check. Open Ports tells you which TCP ports actually accept a connection.

Example output

Here is what the script printed when we ran it on a test computer:

Real terminal output
Scanning 127.0.0.1 - 6 ports, 200 ms timeout each
(connect scan only; scan machines you own or are authorised to test)


No open ports found in the scanned list.

Note: a filtered (firewalled) port looks the same as a closed one to this kind of scan.

Usage

Download the file, then run it from a terminal. On Windows (PowerShell):

powershell -NoProfile -ExecutionPolicy Bypass -File .\Test-OpenPorts.ps1 -Target 127.0.0.1

On Linux or macOS (bash):

bash port-scan.sh 127.0.0.1

Options

-Target <host>
host to scan (default 127.0.0.1 - your own machine)
-Ports <list>
comma list such as 80,443,3000 (default: common services)
-TimeoutMs <n>
milliseconds to wait per port (default 300)

What it does

Limitations

Know these before you rely on it:

Security notes — is this safe to run?

Compare the checksum of the file you downloaded against this value to be sure it was not tampered with en route:

FileSHA-256
Test-OpenPorts.ps1e7ef92a7f82eb55c630f2dfff16948d3496151059c7d964f93217ee37de27bf7
port-scan.sh5014d04bf1e5583f0150bcb903c00c79a44631eee4ebd7750ae3827444ca0925

Verify with Get-FileHash .\Test-OpenPorts.ps1 -Algorithm SHA256 on Windows, sha256sum Test-OpenPorts.ps1 on Linux or macOS.

Alternatives

In context

This tool is one of the steps in the how to check open ports on windows, mac and linux workflow — the guide explains what order to run things in and how to interpret the results.

Source

The complete PowerShell source, so you can audit it before running:

Test-OpenPorts.ps1
<#
.SYNOPSIS
  Test-OpenPorts - checks which TCP ports accept a connection.

.DESCRIPTION
  Connect-scans TCP ports (no raw sockets, no admin rights needed).
  Defaults to localhost and a short list of common service ports.

  Only scan machines you own or have permission to test. A connect attempt
  is recorded in the target's logs.

.EXAMPLE
  powershell -ExecutionPolicy Bypass -File .\Test-OpenPorts.ps1
.EXAMPLE
  powershell -ExecutionPolicy Bypass -File .\Test-OpenPorts.ps1 -Target 127.0.0.1 -Ports 80,443,3000
#>
[CmdletBinding()]
param(
  [string]$Target = '127.0.0.1',
  [string]$Ports = '21,22,25,53,80,110,135,139,143,443,445,993,995,1433,3000,3306,3389,5000,5432,5900,6379,8080,8443,9200,27017',
  [int]$TimeoutMs = 300
)

$portList = @()
foreach ($part in ($Ports -split ',')) {
  $t = $part.Trim()
  if ($t -match '^\d+$') {
    $n = [int]$t
    if ($n -ge 1 -and $n -le 65535) { $portList += $n }
  }
}
$portList = $portList | Sort-Object -Unique
if (-not $portList) {
  Write-Error 'No valid ports given. Use a list like 80,443,3000.'
  exit 1
}

Write-Host ("Scanning {0} - {1} ports, {2} ms timeout each" -f $Target, $portList.Count, $TimeoutMs)
Write-Host '(connect scan only; scan machines you own or are authorised to test)'
Write-Host ''

$open = @()
foreach ($port in $portList) {
  $client = New-Object System.Net.Sockets.TcpClient
  try {
    $task = $client.ConnectAsync($Target, $port)
    if ($task.Wait($TimeoutMs) -and $client.Connected) {
      $open += $port
      Write-Host ('  {0,5}  open' -f $port)
    }
  } catch {
    # closed or filtered: expected for most ports
  } finally {
    $client.Dispose()
  }
}

Write-Host ''
if ($open.Count -eq 0) {
  Write-Host 'No open ports found in the scanned list.'
} else {
  Write-Host ("Open ports ({0}): {1}" -f $open.Count, ($open -join ', '))
}
Write-Host ''
Write-Host 'Note: a filtered (firewalled) port looks the same as a closed one to this kind of scan.'

The bash version:

port-scan.sh
#!/usr/bin/env bash
# port-scan.sh - checks which TCP ports accept a connection.
# Connect scan only (uses bash /dev/tcp). No raw sockets, no root needed.
# Only scan machines you own or are authorised to test.
# Run: bash port-scan.sh [host] [ports]
#   ports is a comma list (default: common services)

set -u

HOST="${1:-127.0.0.1}"
PORTS="${2:-21,22,25,53,80,110,135,139,143,443,445,993,995,1433,3000,3306,3389,5000,5432,5900,6379,8080,8443,9200,27017}"
TIMEOUT_S="${3:-0.3}"

echo "Scanning $HOST - connect scan, ${TIMEOUT_S}s timeout each"
echo "(scan machines you own or are authorised to test)"
echo ""

open=""
old_ifs=$IFS
IFS=','
for port in $PORTS; do
  port=$(echo "$port" | tr -d ' ')
  case "$port" in
    ''|*[!0-9]*) continue ;;
  esac
  if timeout "$TIMEOUT_S" bash -c "echo > /dev/tcp/$HOST/$port" 2>/dev/null; then
    printf '  %5s  open\n' "$port"
    open="$open $port"
  fi
done
IFS=$old_ifs

echo ""
if [ -z "$open" ]; then
  echo "No open ports found in the scanned list."
else
  echo "Open ports:$(echo $open)"
fi
echo ""
echo "Note: a filtered (firewalled) port looks the same as a closed one to this kind of scan."

← All tools