Created
February 27, 2024 20:00
-
-
Save soulemike/5f8c4c9c3686030181b8cabdf50187e4 to your computer and use it in GitHub Desktop.
porttest.ps1
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
$remoteDomain=@( | |
"10.0.0.10", | |
"10.0.0.20", | |
"domain.local" | |
) | |
function New-Task([int]$index,[string]$target,[int]$port,[scriptblock]$ScriptBlock) | |
{ | |
$ps = [Management.Automation.PowerShell]::Create() | |
$res = New-Object PSObject -Property @{ | |
Index = $Index | |
Target = $target | |
Port = $port | |
Busy = $true | |
Success = $null | |
async = $null | |
} | |
[Void] $ps.AddScript($ScriptBlock) | |
[Void] $ps.AddParameter("TaskInfo",$Res) | |
$res.async = $ps.BeginInvoke() | |
$res | |
} | |
$ScriptBlock = { | |
param([Object]$TaskInfo) | |
$TaskInfo.Success = (Test-NetConnection $TaskInfo.Target -Port $TaskInfo.Port).TcpTestSucceeded | |
$TaskInfo.Busy = $false | |
} | |
$connectivityResults=@() | |
foreach($r in $remoteDomain) | |
{ | |
$i=0 | |
$ports=80,443,53,88,135,389,445,636,5985,9389,3268 | |
$results=@() | |
foreach($port in $ports) | |
{ | |
if(($i+1)%50 -eq 0){Start-Sleep -Seconds 5} | |
$results+=New-Task -index $i -target $r -port $port -ScriptBlock $ScriptBlock | |
$i++ | |
} | |
$connectivityResults+=$results | |
} | |
while(($connectivityResults|?{$_.Busy}|measure).Count -gt 0){"Not Done";Start-Sleep -Seconds 1} | |
$connectivityResults|select index,target,port,success | |
$connectivityResults|ConvertTo-Json -Depth 99 -Compress|Out-File .\connectivityResults.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment