#Region sweep
1..254 | ForEach-Object -Parallel { $ip = "10.10.10.$_"; if (Test-Connection -Count 1 -ComputerName $ip -Quiet) { $ip } }
#EndRegion
#Region scan
(iwr -uri 'https://johnhanauer.com/cidr/hensss.txt').Content | ConvertFrom-Csv -Header 'Selected', 'Port', 'Description' | ? { $_.Selected -eq '+' } | % -throttle 50 -par { [pscustomobject]@{ Port = $_.Port; Description = $_.Description; Open = (Test-NetConnection -ComputerName $env:COMPUTERNAME -Port $_.Port -InformationLevel Quiet -WarningAction SilentlyContinue) } }
#EndRegion
function Expand-CIDRNetwork {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[ValidatePattern('^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\/([1-9]|[1-2]\d|3[0-2])$')]
[string]$CIDR
)
process {
$p = $CIDR -split '/'
$baseIP = [System.Net.IPAddress]::Parse($p[0])
$prefixLength = [int]$p[1]
$bytes = $baseIP.GetAddressBytes()
[Array]::Reverse($bytes)
$ipInt = [BitConverter]::ToUInt32($bytes, 0)
$mask = ([math]::pow(2, 32) - 1) - ([math]::pow(2, 32 - $prefixLength) - 1)
$mask = [uint32]$mask
$network = $ipInt -band $mask
$broadcast = $network + ([math]::pow(2, 32 - $prefixLength) - 1)
function Convert-UInt32ToIP([uint32]$ip) {
$b = [BitConverter]::GetBytes($ip)
[Array]::Reverse($b)
return ([System.Net.IPAddress]::new($b)).ToString()
}
$startIP = Convert-UInt32ToIP ($network + 1)
$endIP = Convert-UInt32ToIP ($broadcast - 1)
[PSCustomObject]@{
Network = Convert-UInt32ToIP $network
Broadcast = Convert-UInt32ToIP $broadcast
RangeStart = $startIP
RangeEnd = $endIP
}
}
}