← script library

Network Security Audit Script

Security & AuditingJanuary 11, 2025

This PowerShell script is designed to help you audit network security by checking for open ports on local and remote machines. It will help in identifying potential vulnerabilities that could be exploited in a network environment.

powershell
$targetHost = "localhost" # Change this to the IP or hostname you wish to target

function Check-OpenPorts {
    param (
        [string]$host,
        [int]$startPort = 1,
        [int]$endPort = 1024
    )
    for ($port = $startPort; $port -le $endPort; $port++) {
        $result = Test-NetConnection -ComputerName $host -Port $port
        if ($result.TcpTestSucceeded) {
            Write-Output "$host port $port is open"
        }
    }
}

Check-OpenPorts -host $targetHost

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.