IPAddressRange 4.1.2

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

Install-Package IPAddressRange -Version 4.1.2
dotnet add package IPAddressRange --version 4.1.2
<PackageReference Include="IPAddressRange" Version="4.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IPAddressRange --version 4.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

IPAddressRange Class Library Build status NuGet Package

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

Example

using NetTools;
...
// rangeA.Begin is "192.168.0.0", and rangeA.End is "192.168.0.255".
var rangeA = IPAddressRange.Parse("192.168.0.0/255.255.255.0");
rangeA.Contains(IPAddress.Parse("192.168.0.34")); // is True.
rangeA.Contains(IPAddress.Parse("192.168.10.1")); // is False.
rangeA.ToCidrString(); // is 192.168.0.0/24

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

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

// 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("192.168.0.0/16");
var rangeD2 = IPAddressRange.Parse("192.168.10.0/24");
rangeD1.Contains(rangeD2); // is True.

// IEnumerable<IPAddress> support, it's lazy evaluation.
foreach (var ip in IPAddressRange.Parse("192.168.0.1/23"))
{
    Console.WriteLine(ip);
}

// You can use LINQ via "AsEnumerable()" method.
var longValues = IPAddressRange.Parse("192.168.0.1/23")
  .AsEnumerable()
  .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("192.168.0.1");
var ipEnd = IPAddress.Parse("192.168.0.128");
var ipSubnet = IPAddress.Parse("255.255.255.0");

var rangeE = new IPAddressRange(); // This means "0.0.0.0/0".
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("192.168.0.0-192.168.0.254");
rangeI.ToCidrString();  // is 192.168.0.0/24

Release Note

The release notes is here.

License

Mozilla Public License 2.0

IPAddressRange Class Library Build status NuGet Package

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

Example

using NetTools;
...
// rangeA.Begin is "192.168.0.0", and rangeA.End is "192.168.0.255".
var rangeA = IPAddressRange.Parse("192.168.0.0/255.255.255.0");
rangeA.Contains(IPAddress.Parse("192.168.0.34")); // is True.
rangeA.Contains(IPAddress.Parse("192.168.10.1")); // is False.
rangeA.ToCidrString(); // is 192.168.0.0/24

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

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

// 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("192.168.0.0/16");
var rangeD2 = IPAddressRange.Parse("192.168.10.0/24");
rangeD1.Contains(rangeD2); // is True.

// IEnumerable<IPAddress> support, it's lazy evaluation.
foreach (var ip in IPAddressRange.Parse("192.168.0.1/23"))
{
    Console.WriteLine(ip);
}

// You can use LINQ via "AsEnumerable()" method.
var longValues = IPAddressRange.Parse("192.168.0.1/23")
  .AsEnumerable()
  .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("192.168.0.1");
var ipEnd = IPAddress.Parse("192.168.0.128");
var ipSubnet = IPAddress.Parse("255.255.255.0");

var rangeE = new IPAddressRange(); // This means "0.0.0.0/0".
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("192.168.0.0-192.168.0.254");
rangeI.ToCidrString();  // is 192.168.0.0/24

Release Note

The release notes is here.

License

Mozilla Public License 2.0

Release Notes

v.4.1.2
- Fix: "Contains()" method was broken when using the mask length constructor.

  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 1.4

  • UAP 0.0

    • No dependencies.

NuGet packages (16)

Showing the top 5 NuGet packages that depend on IPAddressRange:

Package Downloads
IPAddressRange.Signed
[Superseded] This package became only metadata package for installing "IPAddressRange" NuGet package, because "IPAddressRange" NuGet package became strong-named assembly. Please consider to installing "IPAddress" NuGet package directly instead of this package. ---------------------------- This library allows you to parse range of IP address string such as "192.168.0.0/24" and "192.168.0.0/255.255.255.0" and "192.168.0.0-192.168.0.255", and can contains check. This library supports both IPv4 and IPv6.
WhoisClient.NET
This library is a WHOIS protocol client used to search owner information by IP address or domain name. This library determines the WHOIS server automatically and queries the referral server recursively. The response of the whois query contains strongly typed values, and the raw output.
ZNetCS.AspNetCore.IPFiltering
A middleware that allows whitelist or blacklist incomming requests based on IP address. It can be configured using single IP address or ranges. It supports single IP, IP range IPv4 and IPv6. There is also possible to ignore specific paths from IP filtering.
IQX.RoleManager.Abstractions
Package Description
WhoisParsers
This allows you to: 1) Download and parse Whois records from bulk whois database dumps of IANA organizations (ARIN, AFRINIC, APNIC, LACNIC, RIPE ) and 2) Crawl and parse RWhois records from RFC 2167 ARIN Referral Whois Servers. It also provides utilities to increment IP addresses and to output Whois databases in TSV format.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on IPAddressRange:

Repository Stars
duyanming/Viper
Anno 是一个微服务快速开发框架,底层通讯可以随意切换 grpc、thrift。自带服务发现、调用链追踪、Cron 调度、限流、事件总线、CQRS 、DDD、类似MVC的开发体验,插件化开发。. Anno is a microservices rapid development framework, the underlying communication can be arbitrary switch GRPC, thrift.Built-in service discovery, call chain tracking, Cron scheduling, current limiting, event bus, CQRS, DDD, similar MVC development experience, plug-in development.
andruzzzhka/BeatSaberMultiplayer

Version History

Version Downloads Last updated
4.1.2 19,843 9/16/2020
4.1.1 15,986 9/4/2020
4.1.0-preview1 75 8/18/2020
4.0.0 414,325 8/31/2019
3.2.2 16,628 8/12/2019
3.2.1 120,607 6/26/2019
3.2.0 571,262 5/1/2018
3.1.1 1,054 4/26/2018
3.1.0 28,517 3/22/2018
3.0.0.1 7,629 3/3/2018
3.0.0-beta 514 2/23/2018
2.2.0 4,730 1/29/2018
2.1.1 32,010 11/28/2017
2.1.1-beta 703 11/20/2017
2.1.0.1 52,543 11/16/2017
2.1.0-alpha 723 11/1/2017
2.0.0.4 50,182 9/15/2017
2.0.0.3 59,168 7/4/2017
2.0.0.3-beta 593 5/29/2017
2.0.0-beta 593 5/19/2017
1.6.2.7 25,739 3/8/2017
1.6.2.6-beta 620 3/1/2017
1.6.2.1-beta 802 11/29/2016
1.6.1 57,582 9/27/2016
1.6.0 25,981 5/23/2016
1.5.0 97,203 10/16/2015
1.4.0.1 3,682 8/22/2015
1.4.0 18,209 6/3/2015
1.3.0.1 2,859 4/1/2015
1.3.0 677 4/1/2015
1.2.1 3,072 2/19/2015
1.2.0 15,585 2/5/2015
1.1.0-beta 2,079 11/4/2014
1.0.6 12,028 3/10/2014
1.0.5 1,668 12/9/2013
1.0.4 758 12/9/2013
1.0.3 744 12/9/2013
1.0.2 7,543 5/28/2012
1.0.1 944 5/22/2012
1.0.0 944 5/17/2012