networking - C# How to know if a subnet is part of a bigger network -


I am working with a BGP table on the Internet (a large file). However, root saponification can be a problem. My main point is, sometimes, large quantities of IPv4 space are announced (i.e., 172.16.0.0/16), but more specific and smaller routes are also declared (i.e., 172.16.64.0/ 18). Therefore there are two unnecessary entries in the BGP table.

I would like to figure out a way to end up with a list of non-redundant IP addresses, only large amounts I might be thinking of comparing them all and storing them in a list. What is the C # method to know if any IP address is part of broad IP address? As::

172.16.64.0/18 172.16.0.0/16 is part of / truth

Thank you for all your help!

alemangui

Use simple math.

The IP address is 4 bytes, Iow is a 32-bit integer. The subnet mask is exactly the same.

Given this, you can use an arithmetic and determine whether it is in or out of the fixed network.

Example:

IP: 192.168.0.1 = C A8 00 01 Subnet: 192.168.0.0 = C800 00 is in the subnet? Thus 0xC0A80001 & amp; 0xC0A80000 == 0xC0A80000 = & gt; True, if a pure work is present in another or not, to answer this question, you can use the same approach, but both numbers are called 'the largest' of subnets. Can move with size.

EG:

  Net A: 172.16.64.0/18 - & gt; AC 10 40 00 Net B: 172.16.0.0/16 - & gt; AC 10 00 00 Applicable with both correct changes and last session, apply AC 10 & amp; AC 10 = AC 10 - & gt; True  

Comments