Skip to content

Instantly share code, notes, and snippets.

@msoftware
Created September 10, 2026 08:26
Show Gist options
  • Select an option

  • Save msoftware/02f36b9a4fbd87138056d2136ab75a35 to your computer and use it in GitHub Desktop.

Select an option

Save msoftware/02f36b9a4fbd87138056d2136ab75a35 to your computer and use it in GitHub Desktop.
Simple portscanner for powershell
$ip = "192.168.238.1"
$ports = 6000..7000
$total = $ports.Count
$openPorts = @()
$i = 0
foreach ($port in $ports) {
$i++
Write-Progress -Activity "Scanning $ip" `
-Status "Port $port ($i of $total)" `
-PercentComplete (($i / $total) * 100)
$tcpClient = New-Object System.Net.Sockets.TcpClient
$connect = $tcpClient.BeginConnect($ip, $port, $null, $null)
$wait = $connect.AsyncWaitHandle.WaitOne(200, $false)
if ($wait -and $tcpClient.Connected) {
Write-Host "Port $port is OPEN" -ForegroundColor Green
$openPorts += $port
}
$tcpClient.Close()
}
Write-Progress -Activity "Scanning $ip" -Completed
Write-Host "`nScan complete. Open ports: $($openPorts -join ', ')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment