Click to See Complete Forum and Search --> : Overlapping IP's in C#


robbinz1985
April 21st, 2008, 10:26 AM
Ok im writing a program in C# and im trying to detect overlappin IP pools or overlapping subnet wildcards if you will. Ive used the NOT logic to turn it from a wildcard to a subnet. Now I have to detect whether an IP is overlapping or not.
An example:

192.168.1.1 255.255.0.0

overlaps

192.168.1.1 255.255.255.0

So I want my code to be able to detect this. Does anyone know anything about this.

Any help is appretiated.

TheCPUWizard
May 10th, 2008, 11:25 PM
This really has nothing to do with network addresses but is really simple set theory.

If you created two sets of ip addresses then you are simply loking for the intersetion of these sets. Brute force is possible (and easy on a good x864 of IA64 box). Each set can be represented by 536,870,912 BYTES.

However this would be a silly way to do it.

You can do it with a 4 level iteration. First create a set of all of the Class A subnets (256 possible including broadcasst). Interset these.

Loop through all of the intersecting elements and create independant ClassB subnets for each one, and again intersect each one/

Repeat for ClassC and then independant Addresses.


This can be optimized even further, but unless you are scanning 10's of thousands of relationships, this should be fast enough.