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
httpClientHttpClientThe HTTP client the requests go through; the caller keeps owning it.
userAgentstringThe User-Agent header the requests send.
apiKeystringThe 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
cancellationTokenCancellationTokenThe 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
ipAddressIPAddressThe IP address.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<IpLocation>
A task whose result is the location.
Exceptions
- HttpRequestException
The request failed.