Created
September 10, 2026 08:26
-
-
Save msoftware/02f36b9a4fbd87138056d2136ab75a35 to your computer and use it in GitHub Desktop.
Simple portscanner for powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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