Class IpApiCoLocationProvider
- Namespace
- VpnHood.Net.IpLocations.Providers.Onlines
- Assembly
- VpnHood.Net.IpLocations.dll
Provides locations from ipapi.co: the country, and the region and city where known.
public class IpApiCoLocationProvider : IIpLocationProvider, ICurrentIpLocationProvider, IDisposable
- Inheritance
-
IpApiCoLocationProvider
- Implements
- Inherited Members
Constructors
IpApiCoLocationProvider(HttpClient, string)
Provides locations from ipapi.co: the country, and the region and city where known.
public IpApiCoLocationProvider(HttpClient httpClient, string userAgent)
Parameters
httpClientHttpClientThe HTTP client the requests go through; the caller keeps owning it.
userAgentstringThe User-Agent header the requests send.
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.