Search code examples
c#ipv6cidr

IPv6 CIDR to range


I have a list of CIDR Ipv6 addresses

2c0f:fe40:8000::/48
2c0f:feb0::/43
2c0f:feb0:20::/45

How can I get the ip range From - To without use of external libraries (not included in the VS install)? This is not a duplicate of convert cidr to range as my question is refering to the IPv6 notation, not IPv4.

Example:

Input: 2c0f:fe40:8000::/48
Output: 2c0f:fe40:8000:0:0:0:0:0 - 2c0f:fe40:8000:ffff:ffff:ffff:ffff:ffff

Solution

  • I wrote a quick solution for your problem without using any external library, here you can find the source code.

    An example about how to use it:

    CidrBlock block = CidrBlock.Parse("2c0f:fe40:8000::/48");
    Console.WriteLine($"Start address: {block.StartAddress.IPAddress}");
    Console.WriteLine($"End address: {block.EndAddress.IPAddress}");
    

    Will return

    Start address: 2c0f:fe40:8000::
    End address: 2c0f:fe40:8000:ffff:ffff:ffff:ffff:ffff
    

    Regards.-