Create Start-Portscan.ps1
This commit is contained in:
37
Start-Portscan.ps1
Normal file
37
Start-Portscan.ps1
Normal file
@@ -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."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user