Simple client for the IPLocate API
$ dotnet add package IPLocateIO.ClientA C# client for the IPLocate.io geolocation API. Look up detailed geolocation and threat intelligence data for any IP address:
See what information we can provide for your IP address.
You can make 1,000 free requests per day with a free account. For higher plans, check out API pricing.
[!NOTE] ❌ Not compatible with .NET Framework (which only supports .NET Standard 2.0)
dotnet add package IPLocateIO.Client
NuGet\Install-Package IPLocateIO.Client
paket add IPLocateIO.Client
Get your free API key from IPLocate.io, and pass it to the IpLocateClientFactory.Client method:
IPLocateClient client = IPLocateClientFactory.Client("YOUR_API_KEY");
using IPLocate;
var client = IPLocateClientFactory.Client("YOUR_API_KEY");
var result = await client.LookupCurrentIpAsync();
Console.WriteLine($"IP: {result.Ip}, Country: {result.Country}");
services.AddHttpClient<IPLocateClient>((sp, http) =>
{
var opts = sp.GetRequiredService<IOptions<MyApiOptions>>();
http.BaseAddress = new Uri(opts.Value.BaseUrl);
http.DefaultRequestHeaders.Add("X-Api-Key", opts.Value.ApiKey);
http.DefaultRequestHeaders.Add("Accept", "application/json");
http.DefaultRequestHeaders.Add("User-Agent", "IPLocateClient/1.0.0");
});
using IPLocate;
var client = IPLocateClientFactory.Client(apiKey:"YOUR_API_KEY", cacheDuration: TimeSpan.FromSeconds(15));
var result = await client.LookupCurrentIpAsync();
Console.WriteLine($"IP: {result.Ip}, Country: {result.Country}");
public static void AddIPLocateClient(this IServiceCollection services)
{
services.AddHttpClient<IPLocateClient>((sp, http) =>
{
var opts = sp.GetRequiredService<IOptions<MyApiOptions>>();
http.BaseAddress = new Uri(opts.Value.BaseUrl);
http.DefaultRequestHeaders.Add("X-Api-Key", opts.Value.ApiKey);
http.DefaultRequestHeaders.Add("Accept", "application/json");
http.DefaultRequestHeaders.Add("User-Agent", "IPLocateClient/1.0.0");
}).AddHttpMessageHandler((sp) =>
{
var opts = sp.GetRequiredService<IOptions<MyApiOptions>>();
return new CacheDelegatingHandler(opts.Value.cacheDuration);
});
}
For complete API documentation, visit iplocate.io/docs.
This project is licensed under the MIT License - see the LICENSE file for details
To run tests for this C# library:
dotnet test