IpApi 2024.12.23.223133

dotnet add package IpApi --version 2024.12.23.223133
                    
NuGet\Install-Package IpApi -Version 2024.12.23.223133
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IpApi" Version="2024.12.23.223133" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IpApi" Version="2024.12.23.223133" />
                    
Directory.Packages.props
<PackageReference Include="IpApi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IpApi --version 2024.12.23.223133
                    
#r "nuget: IpApi, 2024.12.23.223133"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IpApi@2024.12.23.223133
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IpApi&version=2024.12.23.223133
                    
Install as a Cake Addin
#tool nuget:?package=IpApi&version=2024.12.23.223133
                    
Install as a Cake Tool

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

  1. Register the IpApiClient in your service collection:

    services.AddIpApiClient();
    
  2. Inject the IIpApiClient interface 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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