Skip to content

Instantly share code, notes, and snippets.

@Szeraax
Last active January 9, 2019 09:21
Show Gist options
  • Save Szeraax/9b2f49adcbcfa9776bf31cf07e43af89 to your computer and use it in GitHub Desktop.
Save Szeraax/9b2f49adcbcfa9776bf31cf07e43af89 to your computer and use it in GitHub Desktop.
# The "i'm up late and shouldn't be writing code" method.
# License: Public Domain - use however you desire, no strings attached.
# Strings attached: There are none, but you can attribute me in your source code comment if you want to
function Test-PrivateIP {
param(
$IPAddress
)
$PrivateSubnetAddressList =
(([ipaddress]"10.0.0.0").address -band ([ipaddress]"255.0.0.0").address),
(([ipaddress]"172.16.0.0").address -band ([ipaddress]"255.240.0.0").address),
(([ipaddress]"192.168.0.0").address -band ([ipaddress]"255.255.0.0").address),
(([ipaddress]"169.254.0.0").address -band ([ipaddress]"255.255.0.0").address)
if ((([ipaddress]$IPAddress).Address -band ([ipaddress]"255.0.0.0").address) -in $PrivateSubnetAddressList) {
return $IPAddress
}
if ((([ipaddress]$IPAddress).Address -band ([ipaddress]"255.240.0.0").address) -in $PrivateSubnetAddressList) {
return $IPAddress
}
if ((([ipaddress]$IPAddress).Address -band ([ipaddress]"255.255.0.0").address) -in $PrivateSubnetAddressList) {
return $IPAddress
}
}
$IPAddressList =
"10.121.23.2",
"204.23.23.2",
"192.168.6.1",
"192.167.254.3",
"10.0.254.201"
foreach ($IPAddress in $IPAddressList) {
Test-PrivateIP $IPAddress
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment