IPGeoLocation.IPGeolocation
3.0.0
dotnet add package IPGeoLocation.IPGeolocation --version 3.0.0
NuGet\Install-Package IPGeoLocation.IPGeolocation -Version 3.0.0
<PackageReference Include="IPGeoLocation.IPGeolocation" Version="3.0.0" />
<PackageVersion Include="IPGeoLocation.IPGeolocation" Version="3.0.0" />
<PackageReference Include="IPGeoLocation.IPGeolocation" />
paket add IPGeoLocation.IPGeolocation --version 3.0.0
#r "nuget: IPGeoLocation.IPGeolocation, 3.0.0"
#:package IPGeoLocation.IPGeolocation@3.0.0
#addin nuget:?package=IPGeoLocation.IPGeolocation&version=3.0.0
#tool nuget:?package=IPGeoLocation.IPGeolocation&version=3.0.0
IPGeolocation .NET SDK
Official .NET SDK for the IPGeolocation.io IP Location API.
Look up IPv4, IPv6, and domains with /v3/ipgeo and /v3/ipgeo-bulk. Get geolocation, company, ASN, timezone, network, hostname, abuse, user-agent, and security data from one API.
- .NET Standard 2.1 package
- Async client built on
HttpClient - Typed responses plus raw JSON and XML methods
Table of Contents
- Install
- Quick Start
- At a Glance
- Get Your API Key
- Authentication
- Plan Behavior
- Client Configuration
- Available Methods
- Request Options
- Examples
- Response Metadata
- Errors
- Troubleshooting
- Frequently Asked Questions
- Links
Install
dotnet add package IPGeoLocation.IPGeolocation
Install-Package IPGeoLocation.IPGeolocation
<PackageReference Include="IPGeoLocation.IPGeolocation" Version="3.0.0" />
NuGet package: IPGeoLocation.IPGeolocation
Package page: https://www.nuget.org/packages/IPGeoLocation.IPGeolocation
GitHub repository: https://github.com/IPGeolocation/ip-geolocation-api-dotnet-sdk
Quick Start
using System;
using IPGeolocation;
var apiKey = Environment.GetEnvironmentVariable("IPGEO_API_KEY")
?? throw new InvalidOperationException("Set IPGEO_API_KEY first.");
using var client = new IpGeolocationClient(new IpGeolocationClientConfig(apiKey: apiKey));
var response = await client.LookupIpGeolocationAsync(
new LookupIpGeolocationRequest(ip: "8.8.8.8"));
Console.WriteLine(response.Data.Ip); // 8.8.8.8
Console.WriteLine(response.Data.Location?.CountryName); // United States
Console.WriteLine(response.Data.Location?.City);
Console.WriteLine(response.Data.TimeZone?.Name);
Console.WriteLine(response.Metadata.CreditsCharged ?? 0);
Use LookupIpGeolocationRequest and BulkLookupIpGeolocationRequest when you want request validation before the call is sent.
At a Glance
| Item | Value |
|---|---|
| Package | IPGeoLocation.IPGeolocation |
| Namespace | IPGeolocation |
| Supported Endpoints | /v3/ipgeo, /v3/ipgeo-bulk |
| Supported Inputs | IPv4, IPv6, domain |
| Main Data Returned | Geolocation, company, ASN, timezone, network, hostname, abuse, user-agent, currency, security |
| Authentication | API key, request-origin auth for /v3/ipgeo only |
| Response Formats | Structured JSON, raw JSON, raw XML |
| Bulk Limit | Up to 50,000 IPs or domains per request |
| Transport | HttpClient |
Get Your API Key
Create an IPGeolocation account and copy an API key from your dashboard.
- Sign up: https://app.ipgeolocation.io/signup
- Verify your email if prompted
- Sign in: https://app.ipgeolocation.io/login
- Open your dashboard: https://app.ipgeolocation.io/dashboard
- Copy an API key from the
API Keyssection
For server-side code, keep the API key in an environment variable or secret manager. For browser-based single lookups on paid plans, use request-origin auth instead of exposing an API key in frontend code.
Authentication
API Key
using IPGeolocation;
using var client = new IpGeolocationClient(
new IpGeolocationClientConfig(apiKey: Environment.GetEnvironmentVariable("IPGEO_API_KEY")));
Request-Origin Auth
using IPGeolocation;
using var client = new IpGeolocationClient(
new IpGeolocationClientConfig(requestOrigin: "https://app.example.com"));
requestOrigin must be an absolute http or https origin with no path, query string, fragment, or userinfo.
Request-origin auth does not work with /v3/ipgeo-bulk. Bulk lookup always requires apiKey.
If you set both apiKey and requestOrigin, single lookup still uses the API key. The API key is sent as the apiKey query parameter, so avoid logging full request URLs.
Plan Behavior
Feature availability depends on your plan and request parameters.
| Capability | Free | Paid |
|---|---|---|
| Single IPv4 and IPv6 lookup | Supported | Supported |
| Domain lookup | Not supported | Supported |
| Bulk lookup | Not supported | Supported |
Non-English lang |
Not supported | Supported |
| Request-origin auth | Not supported | Supported for /v3/ipgeo only |
Optional modules via include |
Not supported | Supported |
include: ["*"] |
Base response only | All plan-available modules |
Paid plans still need include for optional modules. fields and excludes only trim the response. They do not turn modules on or unlock paid data.
Client Configuration
| Field | Type | Default | Notes |
|---|---|---|---|
apiKey |
string? |
unset | Required for bulk lookup. Optional for single lookup if requestOrigin is set. |
requestOrigin |
string? |
unset | Must be an absolute http or https origin. |
baseUrl |
string |
https://api.ipgeolocation.io |
Override the API base URL. |
connectTimeout |
TimeSpan |
10 seconds |
Time to open the connection. |
readTimeout |
TimeSpan |
30 seconds |
Time to wait while reading the response body. |
The client constructor accepts an IpGeolocationClientConfig. Timeouts are validated before the request is sent.
Available Methods
| Method | Returns | Notes |
|---|---|---|
LookupIpGeolocationAsync(request = null, cancellationToken = default) |
Task<ApiResponse<IpGeolocationResponse>> |
Single lookup. Typed JSON response. |
LookupIpGeolocationRawAsync(request = null, cancellationToken = default) |
Task<ApiResponse<string>> |
Single lookup. Raw JSON or XML string. |
BulkLookupIpGeolocationAsync(request, cancellationToken = default) |
Task<ApiResponse<IReadOnlyList<BulkLookupResult>>> |
Bulk lookup. Typed JSON response. |
BulkLookupIpGeolocationRawAsync(request, cancellationToken = default) |
Task<ApiResponse<string>> |
Bulk lookup. Raw JSON or XML string. |
Dispose() |
void |
Closes the client and releases its transport. |
Typed methods support JSON only. Use the raw methods when you need XML output.
Request Options
| Field | Applies To | Notes |
|---|---|---|
ip |
Single lookup | IPv4, IPv6, or domain. Omit it for caller IP lookup. |
ips |
Bulk lookup | Collection of 1 to 50,000 IPs or domains. |
lang |
Single and bulk | One of en, de, ru, ja, fr, cn, es, cs, it, ko, fa, pt. |
include |
Single and bulk | Collection of module names such as security, abuse, user_agent, hostname, liveHostname, hostnameFallbackLive, geo_accuracy, dma_code, or *. |
fields |
Single and bulk | Collection of field paths to keep, for example location.country_name or security.threat_score. |
excludes |
Single and bulk | Collection of field paths to remove from the response. |
userAgent |
Single and bulk | Overrides the outbound User-Agent header. |
headers |
Single and bulk | Extra request headers as IReadOnlyDictionary<string, string>. |
output |
Single and bulk | ResponseFormat.Json or ResponseFormat.Xml. Typed methods require JSON. |
Examples
The examples below assume you already have a configured client in scope:
using System;
using IPGeolocation;
var apiKey = Environment.GetEnvironmentVariable("IPGEO_API_KEY")
?? throw new InvalidOperationException("Set IPGEO_API_KEY first.");
using var client = new IpGeolocationClient(new IpGeolocationClientConfig(apiKey: apiKey));
Caller IP
Omit ip to look up the public IP of the machine making the request.
var response = await client.LookupIpGeolocationAsync();
Console.WriteLine(response.Data.Ip);
Domain Lookup
Domain lookup is a paid-plan feature.
var response = await client.LookupIpGeolocationAsync(
new LookupIpGeolocationRequest(ip: "ipgeolocation.io"));
Console.WriteLine(response.Data.Ip);
Console.WriteLine(response.Data.Domain); // ipgeolocation.io
Console.WriteLine(response.Data.Location?.CountryName);
Security and Abuse
var response = await client.LookupIpGeolocationAsync(
new LookupIpGeolocationRequest(
ip: "9.9.9.9",
include: new[] { "security", "abuse" }));
Console.WriteLine(response.Data.Security?.ThreatScore);
Console.WriteLine(response.Data.Abuse?.Emails?[0]);
User-Agent Parsing
To parse a visitor user-agent string, pass include: ["user_agent"] and send the visitor string in the request User-Agent header.
using System.Collections.Generic;
const string visitorUa =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9";
var response = await client.LookupIpGeolocationAsync(
new LookupIpGeolocationRequest(
ip: "115.240.90.163",
include: new[] { "user_agent" },
headers: new Dictionary<string, string> { ["User-Agent"] = visitorUa }));
Console.WriteLine(response.Data.UserAgent?.Name);
Console.WriteLine(response.Data.UserAgent?.OperatingSystem?.Name);
The userAgent request field overrides the SDK's default outbound User-Agent header. It takes precedence over headers["User-Agent"].
Filtered Response
var response = await client.LookupIpGeolocationAsync(
new LookupIpGeolocationRequest(
ip: "8.8.8.8",
include: new[] { "security" },
fields: new[] { "location.country_name", "security.threat_score", "security.is_vpn" },
excludes: new[] { "currency" }));
Console.WriteLine(response.Data.Location?.CountryName);
Console.WriteLine(response.Data.Security?.ThreatScore);
Console.WriteLine(response.Data.Security?.IsVpn);
Console.WriteLine(response.Data.Currency is null); // True
Raw XML
var response = await client.LookupIpGeolocationRawAsync(
new LookupIpGeolocationRequest(
ip: "8.8.8.8",
output: ResponseFormat.Xml));
Console.WriteLine(response.Data);
Bulk Lookup
var response = await client.BulkLookupIpGeolocationAsync(
new BulkLookupIpGeolocationRequest(new[] { "8.8.8.8", "1.1.1.1" }));
foreach (var result in response.Data)
{
if (result is BulkLookupSuccess success)
{
Console.WriteLine(success.Data.Ip);
continue;
}
if (result is BulkLookupError error)
{
Console.WriteLine(error.Error.Message);
}
}
Raw Bulk JSON
var response = await client.BulkLookupIpGeolocationRawAsync(
new BulkLookupIpGeolocationRequest(new[] { "8.8.8.8", "1.1.1.1" }));
Console.WriteLine(response.Data);
Response Metadata
Every method returns ApiResponse<T>, where:
Datacontains the typed object or raw response stringMetadatacontains response details such as:CreditsChargedSuccessfulRecordsStatusCodeDurationMsRawHeaders
Example:
Console.WriteLine(response.Metadata.StatusCode);
Console.WriteLine(response.Metadata.DurationMs);
Console.WriteLine(response.Metadata.FirstHeaderValue("content-type"));
Errors
The SDK throws typed exceptions instead of returning error objects for failed HTTP responses.
| Exception | When it happens |
|---|---|
ValidationException |
Invalid config, invalid request values, or typed XML request |
RequestTimeoutException |
Connect timeout or read timeout |
TransportException |
Network or transport failure |
SerializationException |
Request or response serialization failure |
ApiException |
API returned a non-2xx response |
ApiException has status-specific subclasses:
BadRequestExceptionUnauthorizedExceptionForbiddenExceptionNotFoundExceptionMethodNotAllowedExceptionContentTooLargeExceptionUnsupportedMediaTypeExceptionLockedExceptionTooManyRequestsExceptionCustomStatus499ExceptionInternalServerErrorException
Example:
try
{
var response = await client.LookupIpGeolocationAsync(
new LookupIpGeolocationRequest(output: ResponseFormat.Xml));
}
catch (ValidationException error)
{
Console.WriteLine(error.Message);
}
catch (ApiException error)
{
Console.WriteLine((int)error.StatusCode);
Console.WriteLine(error.Message);
}
Troubleshooting
- Bulk lookup always requires
apiKey.requestOriginis not enough. - Typed methods only support JSON. Use the raw methods for XML.
- If you need security, abuse, user-agent, or hostname data, include those modules explicitly.
fieldsandexcludesfilter the response. They do not unlock paid data.requestOriginmust be an origin only. Do not include a path, query string, fragment, or userinfo.
Frequently Asked Questions
<details> <summary>Can I use this SDK without an API key?</summary>
Only for single lookup with paid-plan request-origin auth. Bulk lookup always requires an API key. </details>
<details> <summary>Can I request XML and still get typed models?</summary>
No. Typed methods only support JSON. Use LookupIpGeolocationRawAsync or BulkLookupIpGeolocationRawAsync for XML.
</details>
<details> <summary>Does domain lookup work on the free plan?</summary>
No. Domain lookup is a paid-plan feature. </details>
<details> <summary>How do I get security, abuse, hostname, or user-agent data?</summary>
Pass the right modules in include, for example security, abuse, hostname, or user_agent.
</details>
Links
- Homepage: https://ipgeolocation.io
- IP Location API product page: https://ipgeolocation.io/ip-location-api.html
- Documentation: https://ipgeolocation.io/documentation/ip-location-api.html
- NuGet package: https://www.nuget.org/packages/IPGeoLocation.IPGeolocation
- GitHub repository: https://github.com/IPGeolocation/ip-geolocation-api-dotnet-sdk
| Product | Versions 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. |
-
.NETStandard 2.1
- System.Text.Json (>= 8.0.5)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on IPGeoLocation.IPGeolocation:
| Package | Downloads |
|---|---|
|
Bitspco.Framework.NetCore
5 Layer App Requirement Tools |
|
|
OneRow.GeoIp
Some Geo Utilities. Use as-is. No support. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 137 | 4/9/2026 |
| 2.0.0 | 2,235 | 7/28/2025 |
| 1.1.0 | 44,375 | 7/12/2023 |
| 1.0.10 | 5,671 | 4/1/2022 |
| 1.0.9 | 42,803 | 11/7/2019 |
| 1.0.8 | 2,550 | 9/6/2019 |
| 1.0.7 | 1,779 | 8/26/2019 |
| 1.0.6 | 3,725 | 7/10/2019 |
| 1.0.5 | 28,065 | 11/29/2018 |
| 1.0.4 | 1,923 | 11/28/2018 |
| 1.0.3 | 4,401 | 8/18/2018 |
| 1.0.2 | 2,162 | 8/13/2018 |
| 1.0.1 | 2,047 | 8/13/2018 |
| 1.0.0 | 2,952 | 8/3/2018 |
Replaced the old generated multi-API SDK with the new .NET SDK for the IPGeolocation.io IP Location API.