CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2008
    Posts
    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.

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    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
  •  





Click Here to Expand Forum to Full Width

Featured