Код:
function IsIpAddressInRange {
param(
[string] $ipAddress,
[string] $fromAddress,
[string] $toAddress
)
$ip = [system.net.ipaddress]::Parse($ipAddress).GetAddressBytes()
[array]::Reverse($ip)
$ip = [system.BitConverter]::ToUInt32($ip, 0)
$from = [system.net.ipaddress]::Parse($fromAddress).GetAddressBytes()
[array]::Reverse($from)
$from = [system.BitConverter]::ToUInt32($from, 0)
$to = [system.net.ipaddress]::Parse($toAddress).GetAddressBytes()
[array]::Reverse($to)
$to = [system.BitConverter]::ToUInt32($to, 0)
$from -le $ip -and $ip -le $to
}
$IPAddress="10.9.9.200"
Get-DhcpServerv4Scope | Where {IsIpAddressInRange $IPAddress $_.StartRange $_.EndRange}
Если нет областей больше /24,то можно:
Код:
Get-DhcpServerv4Scope -ScopeId ("10.9.9.200" -replace "\d+$","0")