VPNDetection 6.2.2
See the version list below for details.
dotnet add package VPNDetection --version 6.2.2
NuGet\Install-Package VPNDetection -Version 6.2.2
<PackageReference Include="VPNDetection" Version="6.2.2" />
<PackageVersion Include="VPNDetection" Version="6.2.2" />
<PackageReference Include="VPNDetection" />
paket add VPNDetection --version 6.2.2
#r "nuget: VPNDetection, 6.2.2"
#:package VPNDetection@6.2.2
#addin nuget:?package=VPNDetection&version=6.2.2
#tool nuget:?package=VPNDetection&version=6.2.2
<img src="https://s3.vpndetection.io/vpndetection-public/brand/mark.svg" alt="VPNDetection" height="28"/> VPNDetection .NET Client Library
The official .NET client library for the VPNDetection API.
It tells you whether an IP address is a VPN, residential proxy, Tor node, relay or hosting server.
Getting Started
dotnet add package VPNDetection
Targets .NET 8 and newer.
Usage
No API key needed to start. Unlimited, the free plan, answers ip, is_vpn, Tor and relay detection, is_anycast, hostname, location and asn (the AS's country and RPKI status included), with no daily or monthly cap, with a key or without one.
using VPNDetection;
using var client = new VpnDetectionClient();
var result = await client.LookupAsync("45.83.91.1");
Console.WriteLine(result.IsVpn); // True
Console.WriteLine(result.Location?.Country); // the ISO 3166 country code
Console.WriteLine(result.Asn?.Name); // who runs the announcing network
With an API key
Every paid plan answers every field: is_hosting, is_cdn and the four proxy flags as well, and the provider (its ID and its name), confidence and last-seen detail behind each flag; is_carrier, is_satellite, is_ssh, is_smtp, is_web, is_dns_resolver and is_bittorrent, with the detail behind each; the location's region, city, postal code and coordinates; and the address's company and abuse contact. The plans differ only in how many lookups they include, and a free account tries every field. Create a key in the console, then pass it in:
using var client = new VpnDetectionClient(new VpnDetectionClientOptions
{
ApiKey = Environment.GetEnvironmentVariable("VPNDETECTION_API_KEY"),
});
var result = await client.LookupAsync("45.83.91.1");
Console.WriteLine(result.IsVpn); // True
Console.WriteLine(result.IsHosting); // True, on a paid plan
Console.WriteLine(result.Vpn?.Provider); // nordvpn, on a paid plan
Your own address
var result = await client.MyIpAsync();
Console.WriteLine(result.Ip); // the address we saw this call come from
Same answer LookupAsync would give for that address, and the same cost against your allowance. It is deliberately not cached: which address you are is the whole question, and a machine that moves between networks would otherwise be told where it used to be.
Your plan and usage
var acct = await client.MyEntitlementAsync();
Console.WriteLine(acct.Plan.Name); // Max, what to show
Console.WriteLine(acct.Plan.Key); // max, what to compare against
Console.WriteLine(acct.Usage.Requests); // 580
Console.WriteLine(acct.Usage.WindowEnd); // when the allowance resets
Usage counts against the anniversary of your subscription on a paid plan, not the calendar month and not the billing period, and against the trial on the free plan; it is the same number a lookup is gated on. HardLimit is null on an uncapped plan, which is not the same as zero.
Show Plan.Name and compare against Plan.Key: a plan's name can change, and its key never does.
Batch lookup
Look up many addresses at once. Bogons and cached answers are handled locally, and everything else goes to the batch endpoint in chunks of up to 1000 addresses, in parallel. The batch endpoint needs a paid plan:
var results = await client.LookupBatchAsync(new[] { "45.83.91.1", "8.8.8.8", "1.1.1.1" });
foreach (var (ip, answer) in results)
{
if (!answer.IsSuccess)
{
Console.Error.WriteLine($"{ip}: {answer.Error!.Message}");
continue;
}
Console.WriteLine($"{ip}: {answer.Result!.IsVpn}");
}
Results are keyed by address, in the order you first listed each one, so duplicates in your list collapse into a single entry and one address failing never loses the rest: it carries its error as its value, with the status the API would have given that address on its own.
How many chunks are in flight at once, how many times a failed chunk is retried, and how long each attempt at a chunk may take, are configurable per call:
var results = await client.LookupBatchAsync(manyIps, new BatchOptions
{
Concurrency = 4,
Retries = 4,
RequestTimeout = TimeSpan.FromSeconds(10),
});
Caching
Answers are cached by default, so repeat lookups of the same address are free:
using var client = new VpnDetectionClient();
var result = await client.LookupAsync("45.83.91.1");
Console.WriteLine(result.IsVpn); // True, API request
var result2 = await client.LookupAsync("45.83.91.1");
Console.WriteLine(result2.IsVpn); // True, no API request, result was cached
You can change the default cache variables (max size, TTL, etc) on initialization, or even disable it:
using var client = new VpnDetectionClient(new VpnDetectionClientOptions
{
CacheSize = 50_000,
CacheTtl = TimeSpan.FromHours(6),
});
using var noCache = new VpnDetectionClient(new VpnDetectionClientOptions { CacheEnabled = false });
An answer with TrialExpired or CapReached true is cached for a minute at most, so a renewed trial or a raised cap reaches you within a minute.
The cache belongs to the client instance, never to the process, because two keys can be on different plans and so entitled to different fields.
Private and reserved addresses
Private, loopback, link-local, documentation and multicast addresses (and their IPv6 equivalents, including the 6to4 and Teredo ranges) can never be VPN or proxy infrastructure. The library answers them locally, so they cost no request and no quota:
var result = await client.LookupAsync("192.168.1.1");
result.IsBogon; // True, answered locally with no request
result.IsVpn; // False
The check is available on the client, which is handy when your inputs are addresses anyway:
client.IsBogon("10.0.0.1"); // True
client.IsBogon("8.8.8.8"); // False
It is also available on its own, if you want it without a client:
VPNDetection.Bogon.IsBogon("10.0.0.1"); // True
Errors
Failures throw a VpnDetectionException carrying a Kind and a Retryable flag:
try
{
await client.LookupAsync("1.1.1.1");
}
catch (VpnDetectionException e)
{
Console.Error.WriteLine($"{e.Kind} {e.Retryable} {e.StatusCode}");
}
Kind is one of BadRequest, Unauthorized, Forbidden, RateLimited, QuotaExceeded, ServerError or Network.
Note that RateLimited and QuotaExceeded both arrive as HTTP 429 and are not the same thing. A rate limit is when the API faces extreme traffic bursts and so retrying later works; but a spent quota needs your allowance raised or the window to roll over. The library retries rate limits for you, but not if your quota is exceeded.
Each attempt is abandoned after 30 seconds by default (RequestTimeout on the options), which fails as a retryable Network error. One call can set its own, longer or shorter:
var result = await client.LookupAsync("45.83.91.1", new LookupOptions { RequestTimeout = TimeSpan.FromSeconds(5) });
Database downloads
If your key carries the db.download scope, the licensed databases are available through client.Database. A license covers a database FAMILY, so the IDs below come from its versions. DownloadAsync fetches one to a path, streaming it straight to disk so that nothing bigger than a chunk is ever held in memory; or take the bytes, or the time-limited link to run the transfer yourself:
var databases = await client.Database.ListAsync();
var id = databases[0].Versions[0].Id; // "vpn_ip_extended_v1"
var written = await client.Database.DownloadAsync(id, DatabaseFormat.Mmdb, $"{id}.mmdb");
var bytes = await client.Database.DownloadBytesAsync("cdn_ip_v1", DatabaseFormat.Csvgz);
var url = await client.Database.DownloadUrlAsync(id, DatabaseFormat.Mmdb);
DownloadBytesAsync holds the whole file in memory, and the catalog runs from cdn_ip_v1 at 10 KB to resproxy_ip_90d_v1 at 1.79 GB, so use DownloadAsync for anything you have not measured.
From 5.11.0, each of the three takes a DownloadOptions whose Build is the build a database.updated webhook names, so the file is the one whose sha256 the webhook carries rather than whatever is live by the time you ask. Without it you get the live build. A build is kept 7 days, and one pruned since is an ErrorKind.BadRequest with status 410:
var data = webhook.GetProperty("data"); // a database.updated webhook's JsonElement
var dataset = data.GetProperty("dataset").GetString()!;
await client.Database.DownloadAsync(dataset, DatabaseFormat.Mmdb, $"{dataset}.mmdb",
new DownloadOptions { Build = data.GetProperty("build").GetString() });
Sign in with OAuth (device flow)
A program running on the person's own machine can let them sign in with a browser and pick one of their API keys, instead of asking them to paste it:
using var client = new VpnDetectionClient();
var device = await client.Oauth.DeviceAuthorizationAsync(
"your-client-id", new DeviceAuthorizationOptions { Scope = "account.read apikeys.read apikeys.reveal" });
Console.WriteLine($"Open {device.VerificationUri} and enter {device.UserCode}");
var token = await client.Oauth.PollDeviceTokenAsync("your-client-id", device);
if (token.Apikey is null)
{
throw new InvalidOperationException("no API key came back: none was picked, or it can't be shown again");
}
using var keyed = new VpnDetectionClient(new VpnDetectionClientOptions { ApiKey = token.Apikey });
A denied sign-in throws OauthAccessDeniedException and a code that ran out OauthExpiredTokenException. client.Oauth.RevokeAsync("your-client-id", token.RefreshToken) signs the machine out again. Only a client we registered, such as our CLI, can use the device flow: an app of your own signs people in with the authorization code flow below.
Dependency injection
Register one shared client. The answer cache lives in the client, so one built per request scope starts empty every time and pays for a lookup the last scope already made. In a web app, bound each lookup tightly too, so an unreachable API costs a request seconds rather than minutes:
services.AddSingleton(new VpnDetectionClient(new VpnDetectionClientOptions
{
ApiKey = builder.Configuration["VpnDetection:ApiKey"],
RequestTimeout = TimeSpan.FromSeconds(2),
Retries = 0,
}));
The client also takes an HttpClient, so it can register as a typed client and pick up your handler pipeline, pooling and resilience policies:
services.AddSingleton(new VpnDetectionClientOptions { ApiKey = builder.Configuration["VpnDetection:ApiKey"] });
services.AddHttpClient<VpnDetectionClient>(http => http.Timeout = TimeSpan.FromSeconds(2))
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { AllowAutoRedirect = false });
A typed client is transient, so each scope gets a new VpnDetectionClient with a cache of its own. AllowAutoRedirect = false matters: the database download endpoint answers 302 with the link this library hands back, and .NET's default handler would follow it and fetch the whole database instead. A client that follows redirects is refused with a clear error rather than quietly downloading gigabytes.
A borrowed HttpClient keeps its own Timeout, 100 seconds unless you set one, so RequestTimeout on the options does not apply to it; a per-call RequestTimeout still does.
Sign in with OAuth (authorization code)
An app that can take a browser redirect signs the person in there instead, with a PKCE pair made for that one sign-in:
using var client = new VpnDetectionClient();
var redirectUri = "http://127.0.0.1:8765/callback";
var pkce = client.Oauth.CreatePkce();
var url = client.Oauth.AuthorizationUrl("your-client-id", redirectUri, pkce.Challenge,
new AuthorizationUrlOptions { Scope = "apikeys.use", State = "your-state" });
// Open url in the browser. Its redirect to redirectUri carries code and state.
var token = await client.Oauth.ExchangeAuthorizationCodeAsync("your-client-id", code, pkce.Verifier, redirectUri);
Check that state came back as you sent it before you exchange code, which works once. The client ID can also be the https URL of a client metadata document your app serves, and such an app is never handed a key, so token.Apikey stays null.
Register a client
An app with no client ID, and no client metadata document to use as one, registers itself, then signs in with the ClientId it gets back as the client ID for AuthorizationUrl and ExchangeAuthorizationCodeAsync:
using var client = new VpnDetectionClient();
var registration = await client.Oauth.RegisterAsync(new[] { "http://127.0.0.1:8765/callback" },
new RegisterOptions { ClientName = "Your App" });
Each redirect URI must be https on a public host name, or http on a loopback address, which then matches any port. Nothing is kept until a person approves the client, so an app with no client ID saved can simply register again.
Absent is not false
Unlimited leaves out IsHosting, IsCdn, the four proxy flags, the seven network and service flags from IsCarrier to IsBittorrent, Company, Abuse and the location's finer fields, and of the detail behind each flag it answers only Tor's and relay's; a free-plan key's answer carries TrialExpired, true once its trial is spent, and a paid key's carries CapReached, true once its organization's overage cap is reached and the answer has Unlimited's. The flags are bool?, where null means "not in your plan" rather than "checked, and no".
result.IsHosting ?? false // when you only want the flag
result.IsHosting is null // on Unlimited: not in your plan
result.TrialExpired == true // a free-plan key's trial is spent
result.CapReached == true // a paid key past its overage cap
A value the API adds
A plan's tier, a database's standing and license type, a format and a download's outcome are each a class with a property per value this release knows. A value the API adds later reads as itself rather than failing the call, so compare with == and keep a fallback:
if (database.Standing == Standing.Licensed) { /* download it */ }
database.Standing.Value // "licensed", as the API spells it
database.Standing.IsKnown // false for a value added after this release
Standing.Known // every value this release knows
A format you pass in must be one of DatabaseFormat.Known; any other is an ArgumentOutOfRangeException before a request is made.
Other Libraries
There are official VPNDetection client libraries available for many languages including PHP, Python, Go, Java, Ruby, and many popular frameworks such as Django, Rails, and Laravel. See our GitHub at https://github.com/vpndetection-io for more.
About VPNDetection
VPN Detection API: Accurate anonymity detection identifying VPNs, residential proxies, hosting servers, Tor nodes, CDNs, relays and more.
License
This project is licensed under the MIT 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. |
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on VPNDetection:
| Package | Downloads |
|---|---|
|
VPNDetection.AspNetCore
The official ASP.NET Core middleware for the VPNDetection API. Classifies the visitor behind each request - VPN, residential proxy, Tor, hosting, CDN, relay - and puts the answer on HttpContext. Blocking is opt-in. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.5.0 | 11 | 11/24/2026 |
| 6.4.0 | 55 | 11/24/2026 |
| 6.3.0 | 86 | 11/22/2026 |
| 6.2.2 | 86 | 11/21/2026 |
| 6.2.1 | 89 | 11/20/2026 |
| 6.2.0 | 52 | 11/20/2026 |
| 6.1.1 | 107 | 11/19/2026 |
| 6.1.0 | 122 | 11/18/2026 |
| 6.0.0 | 121 | 11/17/2026 |
| 5.15.0 | 120 | 11/16/2026 |
| 5.14.1 | 122 | 11/15/2026 |
| 5.14.0 | 123 | 11/15/2026 |
| 5.13.2 | 140 | 11/11/2026 |
| 5.13.1 | 117 | 11/11/2026 |
| 5.13.0 | 127 | 11/11/2026 |
| 5.12.2 | 121 | 11/11/2026 |
| 5.12.1 | 90 | 11/11/2026 |
| 5.12.0 | 102 | 11/11/2026 |
| 5.11.1 | 120 | 11/11/2026 |
| 5.11.0 | 128 | 11/7/2026 |