On 28 Aug, 04:28, "Smokey Grindel" <nos...@nospam.comwrote:
Is there a way to check if an IP address is in a subnet range? say I have
the IP
10.10.0.0 and a subnet of 255.255.0.0 and am given the IP 10.10.50.1 and
want to verify that it is in that range.. thanks!
If you have the network address (10.10.0.0) and you have the subnet
mask (255.255.0.0) of the IP and the IP (10.10.50.1) itself you can
use the subnet to determine the network address of the IP and then
compare it to your real value to ensure it is correct.
dim ip as UInt32 = 168440321 'uint32 value for 10.10.50.1
dim subnet as UInt32 = 4294901760 'uint32 value for 255.255.0.0
dim network as UInt32 = 168427520 'uint32 value for 10.10.0.0
if ((ip And subnetMask) = networkAddress) then
'in range
else
'out of range
end if
Please be aware that Jack Jacksons reply is inaccurate. There is no
need to do the:
If (Subnet and SubnetMask) part of the IF, because the operation
(subnet And SubnetMask) will always equal subnet. It's a redundant
statement.
--
Phillip Taylor