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
<PackageReference Include="VpnHood.Net.IpLocations" Version="9.1.874" />
<PackageVersion Include="VpnHood.Net.IpLocations" Version="9.1.874" />
<PackageReference Include="VpnHood.Net.IpLocations" />
paket add VpnHood.Net.IpLocations --version 9.1.874
#r "nuget: VpnHood.Net.IpLocations, 9.1.874"
#:package VpnHood.Net.IpLocations@9.1.874
#addin nuget:?package=VpnHood.Net.IpLocations&version=9.1.874
#tool nuget:?package=VpnHood.Net.IpLocations&version=9.1.874
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
IIpLocationProviderfinds where an address is (GetLocation) and where the device is (GetCurrentLocation);ICurrentIpLocationProvideronly the latter.IIpRangeLocationProvideralso gives each country's IP ranges, from a local database.- Online providers:
IpApiCoLocationProvider,IpInfoIoProvider,IpLocationIoProvider, andCloudflareLocationProviderfor the current location's country. They take yourHttpClientand User-Agent. - Local providers give the country only:
LocalIpLocationProviderholds ranges in memory;LocalIpRangeLocationProviderreads a zip of country ranges, a country at a time.Ip2LocationDbParserbuilds both from IP2Location's LITE DB1 database.VpnHood.Net.IpLocations.Providers.SqliteProviderkeeps the ranges in SQLite instead. CompositeIpLocationProviderandCompositeCurrentIpLocationProvidertry 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, exceptNotSupportedException; your own cancellation ends the lookup withOperationCanceledException, 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 providersVpnHood.Net.IpLocations.Providers.SqliteProvider— the SQLite database and its provider
Requires .NET 11.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- VpnHood.Net.Toolkit (>= 9.1.874)
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 |