Philiprehberger.IpRange
0.3.0
dotnet add package Philiprehberger.IpRange --version 0.3.0
NuGet\Install-Package Philiprehberger.IpRange -Version 0.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Philiprehberger.IpRange" Version="0.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Philiprehberger.IpRange" Version="0.3.0" />
<PackageReference Include="Philiprehberger.IpRange" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Philiprehberger.IpRange --version 0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Philiprehberger.IpRange, 0.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Philiprehberger.IpRange@0.3.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Philiprehberger.IpRange&version=0.3.0
#tool nuget:?package=Philiprehberger.IpRange&version=0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Philiprehberger.IpRange

Parse and match IP addresses against CIDR ranges with IPv4 and IPv6 support.
Installation
dotnet add package Philiprehberger.IpRange
Usage
Parsing and Matching CIDR Ranges
using System.Net;
using Philiprehberger.IpRange;
// Parse a CIDR range and check membership
var range = IpRange.Parse("192.168.1.0/24");
bool match = range.Contains(IPAddress.Parse("192.168.1.42")); // true
// Inspect range boundaries
var cidr = IpCidrRange.Parse("10.0.0.0/8");
Console.WriteLine(cidr.FirstAddress); // 10.0.0.0
Console.WriteLine(cidr.LastAddress); // 10.255.255.255
Console.WriteLine(cidr.PrefixLength); // 8
Matching Against Multiple Ranges
using System.Net;
using Philiprehberger.IpRange;
// Parse comma-separated CIDR ranges into a list
var list = IpRangeList.Parse("10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16");
bool allowed = list.Contains(IPAddress.Parse("172.16.5.1")); // true
// IPv6 ranges work the same way
var ipv6Range = IpCidrRange.Parse("fe80::/10");
bool isLinkLocal = ipv6Range.Contains(IPAddress.Parse("fe80::1")); // true
Checking Range Overlap
using Philiprehberger.IpRange;
var rangeA = IpCidrRange.Parse("192.168.0.0/16");
var rangeB = IpCidrRange.Parse("192.168.1.0/24");
var rangeC = IpCidrRange.Parse("10.0.0.0/8");
bool overlaps = rangeA.Overlaps(rangeB); // true — rangeB is within rangeA
bool separate = rangeA.Overlaps(rangeC); // false — completely disjoint
Safe Parsing and Address Counts
using Philiprehberger.IpRange;
// TryParse never throws — returns false on invalid input
if (IpCidrRange.TryParse("10.0.0.0/8", out var range))
{
System.Numerics.BigInteger total = range.AddressCount; // 16777216
}
if (IpRangeList.TryParse("10.0.0.0/8, 172.16.0.0/12", out var list))
{
Console.WriteLine(list!.Count); // 2
}
Classifying IP Addresses
using System.Net;
using Philiprehberger.IpRange;
// Get the full classification for an address
var classification = IpClassification.Classify(IPAddress.Parse("192.168.1.1"));
Console.WriteLine(classification); // Private
// Quick checks via IpRange helpers
bool isPrivate = IpRange.IsPrivate(IPAddress.Parse("10.0.0.1")); // true
bool isLoopback = IpRange.IsLoopback(IPAddress.Parse("127.0.0.1")); // true
API
IpRange
| Member | Description |
|---|---|
Parse(string cidr) |
Parse a CIDR string and return an IpCidrRange |
IsPrivate(IPAddress address) |
Check if the address is in a private range |
IsLoopback(IPAddress address) |
Check if the address is a loopback address |
IpCidrRange
| Member | Description |
|---|---|
Network |
The network address |
PrefixLength |
The CIDR prefix length |
FirstAddress |
First address in the range |
LastAddress |
Last address in the range |
AddressCount |
Total number of addresses in the range (BigInteger) |
Contains(IPAddress) |
Check if an address falls within this range |
Contains(IpCidrRange) |
Check if another range is fully contained |
Overlaps(IpCidrRange) |
Check if two ranges share any common addresses |
Parse(string cidr) |
Parse a CIDR notation string |
TryParse(string?, out IpCidrRange) |
Try to parse a CIDR string; returns false on invalid input |
IpRangeList
| Member | Description |
|---|---|
Parse(string ranges) |
Parse comma-separated CIDR ranges |
TryParse(string?, out IpRangeList?) |
Try to parse comma-separated CIDR ranges; returns false on invalid input |
Contains(IPAddress) |
Check if any range contains the address |
Count |
Number of CIDR ranges in the list |
IpClassification
| Member | Description |
|---|---|
Classify(IPAddress) |
Returns the classification (Private, Loopback, LinkLocal, Public) |
IsPrivate(IPAddress) |
Check for private ranges (10.0/8, 172.16/12, 192.168/16, fc00::/7) |
IsLoopback(IPAddress) |
Check for loopback (127.0.0.1, ::1) |
IsLinkLocal(IPAddress) |
Check for link-local (169.254/16, fe80::/10) |
Development
dotnet build src/Philiprehberger.IpRange.csproj --configuration Release
Support
If you find this project useful:
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.