$s ="10.72.15.14"
$a ="255.255.255.0"
;Сети
$n ="192.168.72.0"
$t ="10.72.14.0"
$r ="10.72.15.0"
Local $sNetIP = $s, $sNetwork = $n, $sNetMask = $a
Switch _IsIPRange($sNetIP, $sNetwork, $sNetMask)
Case $sNetwork = "192.168.72.0"
ConsoleWrite(StringFormat("Адрес принадлежит сети 192.168.72.0!\n"))
Case $sNetwork = "10.72.14.0"
ConsoleWrite(StringFormat("Адрес принадлежит сети 10.72.14.0!\n"))
Case $sNetwork = "10.72.15.0"
ConsoleWrite(StringFormat("Адрес принадлежит сети 10.72.15.0!\n"))
Case Else
ConsoleWrite(StringFormat("Адрес НЕ принадлежит сети!\n"))
EndSwitch
Func _IsIPRange($s_NetIP, $s_Network, $s_Mask)
$i_NetIP = _IP2Long($s_NetIP)
$i_Network = _IP2Long($s_Network)
$i_CIDR = _IP2Long(_Mask2CIDR($s_Mask))
If ($i_NetIP >= $i_Network) And ($i_NetIP <= ((2^(32 - $i_CIDR)-1) + $i_Network)) Then
Return 1
Else
Return 0
EndIf
EndFunc ;==>_IsIPRange
Func _IP2Long($s_IPAddress)
$i_IPLong = ''
$a_IPAddress = StringSplit($s_IPAddress, ".")
For $i = $a_IPAddress[0] To 1 Step -1
Assign($i, $a_IPAddress[$i], 1)
$i_IPLong += Eval($i) * 256^($a_IPAddress[0] - $i)
Next
Return $i_IPLong
EndFunc ;==>_IP2Long
Func _Mask2CIDR($s_Mask)
$s_Bin = ''
$s_Mask = _IP2Long($s_Mask)
_Dec2Bin($s_Mask, $s_Bin)
$i_Pref = Stringinstr($s_Bin, "0")
If Not $i_Pref Then $i_Pref = 32
Return $i_Pref
EndFunc ;==>_Mask2CIDR
Func _Dec2Bin($i_Dec, ByRef $s_Bin)
If Not $s_Bin Then $s_Bin = ''
If( $i_Dec > 2) Then
_Dec2Bin($i_Dec / 2, $s_Bin)
$s_Bin &= Floor(Mod($i_Dec, 2))
EndIf
EndFunc ;==>_Dec2Bin