Hmm, this doesn't seem to work. I am probably tackling it completely the
wrong way, but basically I want a function to receive two IP's and a subnet
mask and return True if IP1 and 2 are on the same subnet, otherwise false.
I have got this so far:
Private Function IsSameSubnet(By Val IPSource As String, ByVal IPDest As
String, ByVal IPSubnet As String) As Boolean
'return TRUE if the two IP's share the subnet specified, else FALSE
'Get IP Addresses from the strings
Dim SrcIP As IPAddress = IPAddress.Parse (IPSource)
Dim DestIP As IPAddress = IPAddress.Parse (IPDest)
Dim SubIP As IPAddress = IPAddress.Parse (IPSubnet)
'Convert to byte arrays
Dim SrcIPArr As Byte() = SrcIP.GetAddres sBytes
Dim DestIPArr As Byte() = DestIP.GetAddre ssBytes
Dim SubIPArr As Byte() = SubIP.GetAddres sBytes
'Default retval True
IsSameSubnet = True
Dim i as integer
'Loop around each - if the byte "anded" with the subnet ever differs between
source
'and dest then they must be different subnets
For i = 1 To 4
If (SrcIPArr(i) And SubIPArr(i)) <> (DestIPArr(i) And SubIPArr(i)) Then
IsSameSubnet = False
End If
Next
End Function