VpnHood.Net.IpLocations 9.1.874

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

VpnHood.Net.IpLocations

IP location for .NET: find the country, and where known the region and city, of an IP address or of the device's own public address, from online services or from a local database. It is the location layer of VpnHood: the app finds its country and the IP ranges of the countries it splits the tunnel by, and a server finds its own country. It works for any app that needs to place an address.

dotnet add package VpnHood.Net.IpLocations

How it works

  • IIpLocationProvider finds where an address is (GetLocation) and where the device is (GetCurrentLocation); ICurrentIpLocationProvider only the latter. IIpRangeLocationProvider also gives each country's IP ranges, from a local database.
  • Online providers: IpApiCoLocationProvider, IpInfoIoProvider, IpLocationIoProvider, and CloudflareLocationProvider for the current location's country. They take your HttpClient and User-Agent.
  • Local providers give the country only: LocalIpLocationProvider holds ranges in memory; LocalIpRangeLocationProvider reads a zip of country ranges, a country at a time. Ip2LocationDbParser builds both from IP2Location's LITE DB1 database. VpnHood.Net.IpLocations.Providers.SqliteProvider keeps the ranges in SQLite instead.
  • CompositeIpLocationProvider and CompositeCurrentIpLocationProvider try several providers in order. Each gets a token canceled after its timeout (for the current location 5 seconds by default; for an address none), so the timeout holds for a provider that observes it. Failures are logged, except NotSupportedException; your own cancellation ends the lookup with OperationCanceledException, and no other provider is tried.
  • A local lookup of the current location still finds the device's public address online first.

Quick start

The examples below run as a test in CI (IpLocationsReadmeExampleTest.cs). Their namespaces are System.Net, VpnHood.Net.IpLocations.Providers.Offlines and VpnHood.Net.Toolkit.Net.

Look up an address locally

// IP ranges with their countries: two here; in an app, IP2Location's database (Ip2LocationDbParser)
using var provider = new LocalIpLocationProvider([
    new LocalIpLocationProvider.IpRangeInfo {
        IpRange = new IpRange(IPAddress.Parse("1.0.0.0"), IPAddress.Parse("1.0.0.255")),
        CountryCode = "AU"
    },
    new LocalIpLocationProvider.IpRangeInfo {
        IpRange = new IpRange(IPAddress.Parse("5.0.0.0"), IPAddress.Parse("5.0.0.255")),
        CountryCode = "DE"
    }
]);

var location = await provider.GetLocation(IPAddress.Parse("5.0.0.10"), CancellationToken.None);
Console.WriteLine($"{location.CountryName} ({location.CountryCode})"); // Germany (DE)

Save and load the ranges

var path = Path.GetTempFileName(); // in an app, a file in its data folder

// save the ranges once, in their compact binary form...
await using (var file = File.Create(path))
    provider.Serialize(file);

// ...and load them when the app starts
using var loaded = LocalIpLocationProvider.Deserialize(File.OpenRead(path));

Packages

  • VpnHood.Net.IpLocations — the providers
  • VpnHood.Net.IpLocations.Providers.SqliteProvider — the SQLite database and its provider

Requires .NET 11.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on VpnHood.Net.IpLocations:

Package Downloads
VpnHood.AppLib.App

The VpnHood app without its screens: connecting, servers and access keys, settings, accounts, ads, updates, and the API a UI reads the app through. A head adds the platform and the UI.

VpnHood.Core.Server.Access.Managers.FileAccessManagers

An access manager on the server's own file system: access keys and sessions in files, for a VpnHood server that runs without the MANAGER.

VpnHood.Net.IpLocations.Providers.SqliteProvider

SQLite-backed offline IP range provider for VpnHood.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.1.874 0 11/15/2026
9.1.864 191 11/3/2026
9.0.860 202 10/31/2026
9.0.859.16-prerelease 176 10/30/2026
9.0.857 197 10/20/2026
9.0.856 192 10/19/2026
9.0.855 199 10/13/2026
8.2.853.11-prerelease 192 10/5/2026
8.2.853 215 9/23/2026
8.2.852 208 9/23/2026