Skip to content
Go to file

IPAddressRange Class Library Build status NuGet Package

This library allows you to parse range of IP address string such as "" and "" and "", and can contains check. This library supports both IPv4 and IPv6.


using NetTools;
// rangeA.Begin is "", and rangeA.End is "".
var rangeA = IPAddressRange.Parse("");
rangeA.Contains(IPAddress.Parse("")); // is True.
rangeA.Contains(IPAddress.Parse("")); // is False.
rangeA.ToCidrString(); // is

// rangeB.Begin is "", and rangeB.End is "".
var rangeB1 = IPAddressRange.Parse(" -");
rangeB1.Contains(IPAddress.Parse("")); // is True.
rangeB1.Contains(IPAddress.Parse("")); // is False.

// Support shortcut range description. 
// ("" means range of begin: to end:
var rangeB2 = IPAddressRange.Parse("");

// Support CIDR expression and IPv6.
var rangeC = IPAddressRange.Parse("fe80::/10"); 
rangeC.Contains(IPAddress.Parse("fe80::d503:4ee:3882:c586%3")); // is True.
rangeC.Contains(IPAddress.Parse("::1")); // is False.

// "Contains()" method also support IPAddressRange argument.
var rangeD1 = IPAddressRange.Parse("");
var rangeD2 = IPAddressRange.Parse("");
rangeD1.Contains(rangeD2); // is True.

// IEnumerable<IPAddress> support, it's lazy evaluation.
foreach (var ip in IPAddressRange.Parse(""))

// You can use LINQ via "AsEnumerable()" method.
var longValues = IPAddressRange.Parse("")
  .Select(ip => BitConvert.ToInt32(ip.GetAddressBytes(), 0))
  .Select(adr => adr.ToString("X8"));
Console.WriteLine(string.Join(",", longValues);

// Constructors from IPAddress objects.
var ipBegin = IPAddress.Parse("");
var ipEnd = IPAddress.Parse("");
var ipSubnet = IPAddress.Parse("");

var rangeE = new IPAddressRange(); // This means "".
var rangeF = new IPAddressRange(ipBegin, ipEnd);
var rangeG = new IPAddressRange(ipBegin, maskLength: 24);
var rangeH = new IPAddressRange(ipBegin, IPAddressRange.SubnetMaskLength(ipSubnet));

// Calculates Cidr subnets
var rangeI = IPAddressRange.Parse("");
rangeI.ToCidrString();  // is

Release Note

The release notes is here.


Mozilla Public License 2.0


.NET Class Library for range of IP address, both IPv4 and IPv6.




No packages published


You can’t perform that action at this time.