1

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
  • What have you tried to do? – Pavel Anikhouski Jun 29 '20 at 08:55
  • @PavelAnikhouski I tried somehow turning the solution from the question mentioned to work for IPv6, without success – Krystian Borysewicz Jun 29 '20 at 08:56
  • Also, you should understand that your examples are prefixes that get delegated to be subnetted to `/64` networks. You should not be using them as networks on their own, so the first and last addresses do not make that much sense. More likely, you want to get the first and last `/64` subnets for those prefixes. It is pretty easy to get first and last addresses of a `/64` network (using networks of other sizes can cause problems and break IPv6 features). The IPv6 `/64` network is the first address in the network, and you can replace the `::` at the end with `ffff:ffff:ffff:ffff` for the last. – Ron Maupin Jun 29 '20 at 10:24

2 Answers2

1

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.-

0

IPNetwork2 is a great nuget package for almost all your network address related needs.

With it you can easily parse an IPV6 CIDR and get the first and last IP of the range.

var ipnetwork = IPNetwork.Parse("2c0f:fe40:8000::/48");

Console.WriteLine("FirstUsable : {0}", ipnetwork.FirstUsable);
Console.WriteLine("LastUsable : {0}", ipnetwork.LastUsable);

The source is available at https://github.com/lduchosal/ipnetwork.

Karl-Johan Sjögren
  • 16,544
  • 7
  • 59
  • 68