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
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:
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.1On Linux or macOS (bash):
bash port-scan.sh 127.0.0.1Options
-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
- Connect-scans TCP ports using a plain socket - no raw sockets, no special privileges
- Ships a sensible default list of common service ports
- Custom lists via -Ports
- Scans each port with a short timeout, so a full list finishes quickly on a local host
Limitations
Know these before you rely on it:
- A connect scan is not stealthy: the target sees the connection attempt in its logs
- Filtered or firewalled ports look identical to closed ports - absence of an answer is not proof of nothing listening
- No service banner or version detection; it cannot tell you what is running, only that something accepted the connection
- TCP only: UDP services are not covered
- Scanning a host you do not own or administer can be illegal - this tool is for machines you control
Security notes — is this safe to run?
- Only scan machines you own or have written permission to test
- Read the source before running: it opens outbound sockets and prints results, nothing else
- If you need real reconnaissance (stealth scans, version detection, UDP), use nmap - it is the established, audited standard
- For finding what is listening locally, a native lister (netstat, ss, lsof) is faster and does not touch the network
Compare the checksum of the file you downloaded against this value to be sure it was not tampered with en route:
| File | SHA-256 |
|---|---|
Test-OpenPorts.ps1 | e7ef92a7f82eb55c630f2dfff16948d3496151059c7d964f93217ee37de27bf7 |
port-scan.sh | 5014d04bf1e5583f0150bcb903c00c79a44631eee4ebd7750ae3827444ca0925 |
Verify with Get-FileHash .\Test-OpenPorts.ps1 -Algorithm SHA256 on Windows, sha256sum Test-OpenPorts.ps1 on Linux or macOS.
Alternatives
- nmap — the standard: stealth scans, version detection, NSE scripting
- ss -tulpn / netstat -ano — native local listening-port lists on Linux and Windows
- TCPView — Windows GUI from Sysinternals, live process-to-port mapping
- lsof -i — macOS and Linux, shows the process behind each connection
Other tools on this site
- System Report — Check your PC specs: CPU, RAM, disk space and network — one free script, no install.
- Disk Usage — C drive full? Find which folder is using the most disk space on Windows, Mac or Linux.
- Large Files — Find the largest files on your PC — forgotten downloads, old backups, duplicate videos.
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:
<#
.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:
#!/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."