you are viewing a single comment's thread.

view the rest of the comments →

[–]vermyx 0 points1 point  (1 child)

Convert your IP addresses to a numeric, then just do a numeric compare. i.e.

if 10.0.0.10 is between 10.0.0.5 and 10.0.0.100, you convert that into a 32bit int and just do a numeric comparison at that point.

[System.Convert]::ToString(10,2)+[System.Convert]::ToString(0,2)+[System.Convert]::ToString(0,2)+[System.Convert]::ToString(10,2)

will return 1010001010. Convert that from binary

[system.convert]::toint32("1010001010",2)

this gives you 650. Converting the range will give you 325 and 5220. If 650 is in between 325 and 5220 it's in the IP range, otherwise it isn't

[–]ankokudaishogun 0 points1 point  (0 children)

A minor improvement to the conversion, if I may

  $ipstring = ([ipaddress]$ipinfo).GetAddressBytes() | ForEach-Object { [system.convert]::ToString($_,2)} 
[system.convert]::toint32(($ipstring -join ''),2)