SetNet.GeoBlock 1.2.0

dotnet add package SetNet.GeoBlock --version 1.2.0
                    
NuGet\Install-Package SetNet.GeoBlock -Version 1.2.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="SetNet.GeoBlock" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SetNet.GeoBlock" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="SetNet.GeoBlock" />
                    
Project file
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 SetNet.GeoBlock --version 1.2.0
                    
#r "nuget: SetNet.GeoBlock, 1.2.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 SetNet.GeoBlock@1.2.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=SetNet.GeoBlock&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=SetNet.GeoBlock&version=1.2.0
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/Povstalez/SetNet/master/assets/icon.png" alt="SetNet" width="96"> </p>

SetNet.GeoBlock

Reject connections by country of origin for SetNet.

Filter incoming connections by the peer's geographic location — a blocklist ("everyone except these countries") or an allowlist ("only these countries"). Blocked peers are kicked the moment they connect, before any application frame is processed. The GeoIP lookup is pluggable via IGeoResolver, so you back it with whatever you already use — MaxMind GeoLite2, IP2Location, an HTTP GeoIP API, or a static map for tests. This package ships no database. Added by composition — no base class.

Install

dotnet add package SetNet
dotnet add package SetNet.GeoBlock

Usage

Block specific countries

var geo = server.UseGeoBlock(myResolver, new GeoBlockOptions
{
    Policy = GeoPolicy.Blocklist,
    Countries = new[] { "KP", "RU" },   // ISO 3166-1 alpha-2, case-insensitive
});

geo.Blocked += (peer, country) =>
    Console.WriteLine($"blocked {peer.RemoteEndPoint} ({country ?? "unknown"})");

Allow only specific countries

server.UseGeoBlock(myResolver, new GeoBlockOptions
{
    Policy = GeoPolicy.Allowlist,
    Countries = new[] { "UA", "PL" },
    BlockUnknown = true,   // also reject peers whose country can't be resolved
});

Implementing IGeoResolver

public sealed class MaxMindResolver : IGeoResolver
{
    private readonly DatabaseReader _db = new("GeoLite2-Country.mmdb");
    public string? CountryOf(IPAddress address)
        => _db.TryCountry(address, out var r) ? r?.Country?.IsoCode : null;
}

API

server.UseGeoBlock(IGeoResolver resolver, GeoBlockOptions options)GeoBlock

GeoBlockOptions Meaning
GeoPolicy Policy Blocklist (reject listed) or Allowlist (reject unlisted). Default Blocklist.
IReadOnlyCollection<string> Countries ISO alpha-2 codes the policy applies to (case-insensitive).
bool BlockUnknown Reject peers whose country can't be resolved. Default false (allow).

GeoBlock

Member Purpose
event Action<BasePeer, string?> Blocked fired when a peer is kicked (its country, or null if unknown)

IGeoResolverstring? CountryOf(IPAddress address) (return null when unknown).

Notes

  • Needs a real remote endpoint. GeoBlock reads peer.RemoteEndPoint?.Address; transports that don't expose one (e.g. the in-memory test transport) resolve to null → treated per BlockUnknown. TCP/UDP/WebSocket all expose the IP.
  • Ships no GeoIP data. You supply the resolver and its database/service; keep the DB updated for accuracy.
  • Kick-on-connect, not a gate chain. Blocked peers are disconnected immediately via PeerConnected; this is complementary to (and composes with) SetNet.BanList and SetNet.Auth.
  • Geo is coarse. VPNs/proxies defeat country filtering; use it for compliance/region-locking, not as a security boundary.

Documentation & source

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 105 8/5/2026
1.1.0 121 7/2/2026