.NET SDK · Feature

IP Geolocation in .NET

Turn any IP address into geolocation, network, and threat intelligence with one call. The LookupAsync method on the official IpApiIo client returns the country, city, coordinates, timezone, ISP, and ASN of an IP — plus the SuspiciousFactors flags used for fraud screening — in a single typed response.

Trusted by thousands of businesses
Fast JSON API responses
Real-time validation
Simple integration, SDKs & examples
What it does

Geolocation without browser GPS

IP-based geolocation works entirely server-side — no permission prompt, no client SDK, and it works for every visitor and every log line you already have. ip-api.io resolves an IP to a physical location and, uniquely, returns security signals (VPN, proxy, Tor, datacenter, threat) in the same response, so you can localize content and screen for fraud in one round trip.

Prerequisites

  • A .NET 6+ project with an async entry point
  • The IpApiIo package added (dotnet add package IpApiIo)
  • A free ip-api.io API key
1

Geolocate one IP with LookupAsync

Pass any IPv4 or IPv6 address, or use LookupAsync() to geolocate the caller's own IP. Nullable fields are string? / double? — null-check before use.

var client = new IpApiClient(Environment.GetEnvironmentVariable("IP_API_IO_KEY")!);

var info = await client.LookupAsync("8.8.8.8");

Console.WriteLine(info.Ip);                          // "8.8.8.8"
Console.WriteLine(info.Isp);                         // "Google LLC"
Console.WriteLine(info.Location.Country);            // "United States"
Console.WriteLine(info.SuspiciousFactors.IsDatacenter); // True

Resolve the IP of the machine making the request by calling LookupAsync():

var me = await client.LookupAsync();
Console.WriteLine(me.Ip);
Behind a proxy? Pass the real client IP from the X-Forwarded-For header to LookupAsync(ip) rather than relying on the socket address. See the SDK overview for an ASP.NET Core example.
2

Geolocate up to 100 IPs with LookupBatchAsync

Enrich logs, sign-up events, or historical data without a round trip per IP. The SDK throws if the list is empty or longer than 100.

var batch = await client.LookupBatchAsync(
    new[] { "8.8.8.8", "1.1.1.1", "9.9.9.9" });

Console.WriteLine(batch.TotalProcessed);    // 3
Console.WriteLine(batch.SuccessfulLookups); // 3
Console.WriteLine(batch.FailedLookups);     // 0

foreach (var (ip, info) in batch.Results)
    Console.WriteLine($"{ip} {info.SuspiciousFactors.IsVpn}");
Reference

Response reference

LookupAsync resolves to a typed IpInfo. Nullable fields are string? / double?null for private or unrecognized addresses.

PropertyTypeDescription
IpstringThe looked-up address
Ispstring?Internet service provider
Asnstring?Autonomous system the IP belongs to
LocationLocationCountry, CountryCode, City, Latitude, Longitude, Zip, Timezone, LocalTime, LocalTimeUnix, IsDaylightSavings (nullable)
SuspiciousFactorsSuspiciousFactorsIsProxy, IsVpn, IsTorNode, IsDatacenter, IsSpam, IsCrawler, IsThreat
FAQ

Frequently asked questions

How do I get the location of an IP address in C#?

Add IpApiIo, construct an IpApiClient with your API key, and await client.LookupAsync(ip). The returned IpInfo has a Location object with country, city, latitude, longitude and timezone, plus a SuspiciousFactors object with VPN/proxy/Tor flags.

How do I geolocate the caller's own IP?

Call await client.LookupAsync() with no IP argument and the API resolves the IP from the request. Behind a proxy, pass the real client IP from the X-Forwarded-For header to client.LookupAsync(ip) instead.

How do I look up many IP addresses at once?

Use await client.LookupBatchAsync(ips) with up to 100 addresses in one request. It returns Results (an IReadOnlyDictionary<string, IpInfo>) plus TotalProcessed, SuccessfulLookups and FailedLookups.

Why are some fields nullable?

Nullable location fields such as Country and City are string? because they're absent for private ranges or unrecognized addresses — null-check before use. Boolean flags like IsVpn are plain bool.

Start building with the ip-api.io .NET SDK

Run dotnet add package IpApiIo, drop in your free API key, and ship in minutes — one async client for geolocation, fraud detection, and email validation.

Need support?

Explore how IP-API.io can enhance your security, provide robust bot protection, and improve IP geolocation accuracy for your applications.

Contact Support

Found a bug in the SDK?

The IpApiIo package is open source. Open an issue or pull request on GitHub and we'll take a look.

Open on GitHub