Windows Powershell Port Scanner

Powershell code to list open ports when you are on a Windows Machine without nmap!


$ip = "IP_Address_Here"
$ports = 1..1024  # Define the range of ports to scan
$openPorts = @()

foreach ($port in $ports) {
    $tcpConnection = Test-NetConnection -ComputerName $ip -Port $port
    if ($tcpConnection.TcpTestSucceeded) {
        $openPorts += $port
    }
}

# Display the first four open ports
$openPorts[0..3] -join ", "

Last updated