Skip to content

Instantly share code, notes, and snippets.

@jtuttas
Created May 31, 2014 13:45
Show Gist options
  • Save jtuttas/6f73ba9f1c7e952ac4f6 to your computer and use it in GitHub Desktop.
Save jtuttas/6f73ba9f1c7e952ac4f6 to your computer and use it in GitHub Desktop.
function ipinfo($ip) {
$ip
[int[]]$x = $ip.Split(".")
if($x[0] -le 127)
{
"Class A"
}
elseif($x[0] -gt 127 -and $x[0] -le 191)
{
"Class B"
}
elseif($x[0] -gt 191 -and $x[0] -le 223)
{
"Class C"
}
if ($x[0] -ge 1 -and $x[0] -le 127) {
"Default Subnet 255.0.0.0"
}
elseif ($x[0] -ge 128 -and $x[0] -le 191) {
"Default Subnet 255.255.0.0"
}
elseif ($x[0] -ge 192 -and $x[0] -le 233) {
"Default Subnet 255.255.255.0"
}
if ($x[0] -eq 10) {
return "private IP"
}
elseif ($x[0] -eq 172 -and ($x[1] -ge 16 -and $x[1] -le 31)) {
return "private IP"
}
elseif ($x[0] -eq 192 -and $x[1] -eq 168) {
return "private IP"
}
else {
return "public ip"
}
}
ipinfo "192.178.178.6"
ipinfo "10.16.192.1"
ipinfo "172.32.4.5"
ipinfo "172.32.4.5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment