IpApi 2024.12.23.223133
dotnet add package IpApi --version 2024.12.23.223133
NuGet\Install-Package IpApi -Version 2024.12.23.223133
<PackageReference Include="IpApi" Version="2024.12.23.223133" />
<PackageVersion Include="IpApi" Version="2024.12.23.223133" />
<PackageReference Include="IpApi" />
paket add IpApi --version 2024.12.23.223133
#r "nuget: IpApi, 2024.12.23.223133"
#:package IpApi@2024.12.23.223133
#addin nuget:?package=IpApi&version=2024.12.23.223133
#tool nuget:?package=IpApi&version=2024.12.23.223133
IpApi.Net
IpApi.Net is a .NET wrapper for IPQuery IP API, making it easy to query IP-related information in your .NET projects.
Installation
To get started, install the IpApi NuGet package:
dotnet add package IpApi
Usage
Register the IpApiClient in your service collection:
services.AddIpApiClient();Inject the
IIpApiClientinterface into your constructor:public class MyService { private readonly IIpApiClient _ipApiClient; public MyService(IIpApiClient ipApiClient) { _ipApiClient = ipApiClient; } public async Task DoSomethingAsync(CancellationToken cancellationToken) { var myIp = await _ipApiClient.QueryMyIpAsync(cancellationToken); var ipInfo = await _ipApiClient.QueryIpAsync("8.8.8.8", cancellationToken); } }
Methods
The IIpApiClient interface exposes the following methods:
Task<string> QueryMyIpAsync(CancellationToken cancellationToken)
Retrieves your public IP address.
Task<IpInfo?> QueryIpAsync(string ip, CancellationToken cancellationToken)
Retrieves information about a specific IP address.
- Parameters:
ip: The IP address to query.cancellationToken: A token to cancel the operation.
Task<IpInfo[]?> QueryIpsAsync(string[] ips, CancellationToken cancellationToken)
Retrieves information about a collection of IP addresses.
- Parameters:
ips: An array of IP addresses to query.cancellationToken: A token to cancel the operation.
Example
var myIp = await _ipApiClient.QueryMyIpAsync(cancellationToken);
Console.WriteLine($"My public IP: {myIp}");
var ipInfo = await _ipApiClient.QueryIpAsync("8.8.8.8", cancellationToken);
Console.WriteLine($"IP Info: {ipInfo?.City}, {ipInfo?.Country}");
var ipInfos = await _ipApiClient.QueryIpsAsync(new[] {"8.8.8.8", "1.1.1.1"}, cancellationToken);
foreach (var info in ipInfos ?? Array.Empty<IpInfo>())
{
Console.WriteLine($"IP: {info.Ip}, City: {info.City}, Country: {info.Country}");
}
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- Microsoft.Extensions.Http (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2024.12.23.223133 | 137 | 12/23/2024 |
| 2024.12.20.152836 | 117 | 12/20/2024 |