Aspnetcore.docs: IP Address range

Created on 10 Oct 2018  ·  8Comments  ·  Source: dotnet/AspNetCore.Docs

Hi, I needed to safelist a range of IPv4 and IPv6 addresses by Cloudflare but unfortunately this article didn't help me as it only shows how to safelist individual IP addresses rather then ranges of IP addresses. I've implemented a small NuGet package which can help to overcome this problem. Maybe it's worth mentioning it here: https://github.com/dustinmoris/Firewall

Edit by @Rick-Anderson
1.7 K PV/month


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

P2

Most helpful comment

Ah, @blowdart, figures...

All 8 comments

@Tratcher Can Host Filtering Middleware (Kestrel edge) or Forwarded Headers Middleware (reverse proxy) work in the same capacity for this scenario? I understand Host Filtering Middleware doesn't offer a 'range' option.

I didn't even know we had that doc. Who reviewed it? It needs a little work (it's really inefficient).

We don't have middleware that filter the client IP directly, but the Forwarded Headers Middleware does filter reverse proxy IPs this way. You could take the IPNetwork class from HttpOverrides and use it to filter based on subnet ranges.

Ah, @blowdart, figures...

@dustinmoris
You can use NetTools.IPAddressRange for this:

var whitelistIpRange = IPAddressRange.Parse("13.108.0.0/14");
if (whitelistIpRange.Contains(remoteIp))
{
    // do something
}

IPAddressRange.cs

Thanks for contacting us.
We don’t have the resources to invest in this area, so we are closing the issue. Should your request generate enough 👍 responses, we’ll reconsider.

This implementation is throwing an exception on Asp.net core 2.2, please check this: System.InvalidOperationException: 'A suitable constructor for type 'AdminSafeListMiddleware' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.'

Comments on closed issues are not tracked, please open a new issue with the details for your scenario.

@skwebies please show your usage, that's the error you get when you don't pass in enough parameters.

Was this page helpful?
0 / 5 - 0 ratings