Table of Contents

Class IpLocationIoProvider

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

Provides locations from ip2location.io: the country, and the region and city where known.

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

Constructors

IpLocationIoProvider(HttpClient, string, string?)

Provides locations from ip2location.io: the country, and the region and city where known.

public IpLocationIoProvider(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.