1: private static bool CheckWhetherInSameNetwork(string firstIP, string subNet, string secondIP )
2: {
3: uint subnetmaskInInt = ConvertIPToUint(subNet);
4: uint firstIPInInt = ConvertIPToUint(firstIP);
5: uint secondIPInInt = ConvertIPToUint(secondIP);
6: uint networkPortionofFirstIP = firstIPInInt & subnetmaskInInt;
7: uint networkPortionofSecondIP = secondIPInInt & subnetmaskInInt;
8: if (networkPortionofFirstIP == networkPortionofSecondIP)
9: return true;
10: else
11: return false;
12: }
13:
14: static public uint ConvertIPToUint(string ipAddress)
15: {
16: System.Net.IPAddress iPAddress = System.Net.IPAddress.Parse(ipAddress);
17: byte[] byteIP = iPAddress.GetAddressBytes();
18: uint ipInUint = (uint)byteIP[3] << 24;
19: ipInUint += (uint)byteIP[2] << 16;
20: ipInUint += (uint)byteIP[1] << 8;
21: ipInUint += (uint)byteIP[0];
22: return ipInUint;
23: }