From c75e3c2928567471c24c06fb1fabb21a75b3603c Mon Sep 17 00:00:00 2001 From: David Morton Date: Thu, 21 Jul 2022 10:05:36 -0500 Subject: [PATCH] Create Start-Portscan.ps1 --- Start-Portscan.ps1 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Start-Portscan.ps1 diff --git a/Start-Portscan.ps1 b/Start-Portscan.ps1 new file mode 100644 index 0000000..b59b3d5 --- /dev/null +++ b/Start-Portscan.ps1 @@ -0,0 +1,37 @@ +function Start-Portscan{ + [CmdletBinding()] + param ( + #Variable for network address + [Parameter(Mandatory=$true,ValueFromPipeline)] + [String[]] + $IPAddress, + + #Variable for Port value if defined; otherwise range 1..65535 + [Parameter(Mandatory=$false, ValueFromPipeline)] + [String[]] + $Ports + ) + + $range=1..254 + $ErrorActionPreference='SilentyContinue' + if($null -eq $Ports){ + $Ports=1..65535 + } + $NetworkAddress=($IPAddress.Split(".")[0..2]) -join(".") + foreach($add in $range){ + $ip="{0}.{1}" -f $NetworkAddress,$add + if(Test-Connection -Count 1 -ComputerName $ip){ + $Ports | ForEach-Object -ThrottleLimit 5 -Parallel{ + Write-Progress "Scanning Network" $ip -PercentComplete (($_/$Ports.count)*100) + $Socket = New-Object System.Net.Sockets.TcpClient($ip, $_) + if($Socket.Connected){ + Write-Output "$ip port $_ is open." + $Socket.Close() + } + else{ + Write-Output "$ip port $_ is not open." + } + } + } + } +} \ No newline at end of file