Table of Contents

Class IpInfoIoProvider

Namespace
VpnHood.Net.IpLocations.Providers.Onlines
Assembly
VpnHood.Net.IpLocations.dll

Provides locations from ipinfo.io: the country, and the region, without diacritics, and city where known.

public class IpInfoIoProvider : IIpLocationProvider, ICurrentIpLocationProvider, IDisposable
Inheritance
IpInfoIoProvider
Implements
Inherited Members

Constructors

IpInfoIoProvider(HttpClient, string, string?)

Provides locations from ipinfo.io: the country, and the region, without diacritics, and city where known.

public IpInfoIoProvider(HttpClient httpClient, string userAgent, string? apiKey)

Parameters

httpClient HttpClient

The HTTP client the requests go through; the caller keeps owning it.

userAgent string

The User-Agent header the requests send.

apiKey string

The API key, or null; the current location's lookup sends none.

Methods

Dispose()

Does nothing: the provider holds nothing to release.

public void Dispose()

GetCurrentLocation(CancellationToken)

Finds where this device's public IP address is.

public Task<IpLocation> GetCurrentLocation(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<IpLocation>

A task whose result is the location.

Exceptions

NotSupportedException

The provider does not support the lookup.

HttpRequestException

The request failed.

GetLocation(IPAddress, CancellationToken)

Finds where an IP address is.

public Task<IpLocation> GetLocation(IPAddress ipAddress, CancellationToken cancellationToken)

Parameters

ipAddress IPAddress

The IP address.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<IpLocation>

A task whose result is the location.

Exceptions

HttpRequestException

The request failed.