Created
February 4, 2022 14:51
-
-
Save mrk21/11a7f29c4fbd4cf28e892ef8a6695a62 to your computer and use it in GitHub Desktop.
PowerScript: Network IP
This file contains 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
function Get-Network-From-CIDR([String]$CIDR) { | |
$Parsed = $CIDR -split "/" | |
$IP = [IPAddress]$Parsed[0] | |
$Length = [Int]$Parsed[1] | |
$SubnetMask = [IPAddress](([Math]::Pow(2, 32) - 1) -bxor ([Math]::Pow(2, (32 - $Length)) - 1)) | |
$IP = [IPAddress]($IP.Address -band $SubnetMask.Address) | |
return New-Object PSObject -Property @{ | |
IP = $IP; | |
SubnetMask = $SubnetMask | |
} | |
} | |
function Test-Including-Network([IPAddress]$IP, [PSObject]$Network) { | |
$IPNetwork = [IPAddress]($IP.Address -band $Network.SubnetMask.Address) | |
return $IPNetwork.Address -eq $Network.IP.Address | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment