|
-
April 21st, 2008, 10:26 AM
#1
Overlapping IP's in C#
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.
-
May 10th, 2008, 11:25 PM
#2
Re: Overlapping IP's in C#
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.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|