Class Ip2LocationDbParser
- Namespace
- VpnHood.Net.IpLocations.Providers.Offlines
- Assembly
- VpnHood.Net.IpLocations.dll
Provides the means to build the local location databases from IP2Location's LITE DB1 CSV, which maps IP ranges to countries.
public static class Ip2LocationDbParser
- Inheritance
-
Ip2LocationDbParser
- Inherited Members
Methods
BuildLocalIpLocationDb(Stream, string, CancellationToken)
Builds the file Deserialize(Stream, string?) reads.
public static Task BuildLocalIpLocationDb(Stream csvStream, string outputFile, CancellationToken cancellationToken)
Parameters
csvStreamStreamIP2Location's CSV; it is closed after.
outputFilestringThe file to write; an existing one is overwritten.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.- FormatException
A row has an address that is not a number.
BuildLocalIpRangeLocationDb(Stream, string, CancellationToken)
Builds the zip LocalIpRangeLocationProvider reads, with an entry of IP ranges per country
(cc.ips), stamped so an app can tell the build.
public static Task BuildLocalIpRangeLocationDb(Stream csvStream, string outputZipFile, CancellationToken cancellationToken)
Parameters
csvStreamStreamIP2Location's CSV; it is closed after.
outputZipFilestringThe zip file to write; an existing one is overwritten.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.- FormatException
A row has an address that is not a number.
ParseIp2LocationCsv(Stream, CancellationToken)
Reads IP2Location's CSV into each country's IP ranges.
public static Task<Dictionary<string, List<IpRange>>> ParseIp2LocationCsv(Stream ipLocationsCsvStream, CancellationToken cancellationToken)
Parameters
ipLocationsCsvStreamStreamIP2Location's CSV; it is closed after.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Dictionary<string, List<IpRange>>>
A task whose result maps each country's code, in lower case, to its ranges.
Remarks
Rows with no country (-) and rows without four columns are skipped, a quoted column keeping its commas;
um, the US Minor Outlying Islands, counts as us; IPv4-mapped IPv6 ranges become IPv4 ones.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.- FormatException
A row has an address that is not a number.
UpdateLocalDb(string, string, bool, TimeSpan?, CancellationToken)
Downloads IP2Location's LITE DB1 database and rebuilds a local database from it, unless the file is newer than
interval.
public static Task UpdateLocalDb(string filePath, string apiKey, bool forIpRange, TimeSpan? interval, CancellationToken cancellationToken)
Parameters
filePathstringThe database file to write.
apiKeystringThe IP2Location download token.
forIpRangebooltrue to build the zip LocalIpRangeLocationProvider reads; false for the file Deserialize(Stream, string?) reads.
intervalTimeSpan?How old the file may be before it is rebuilt, or null for 7 days.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Exceptions
- HttpRequestException
The download failed.
- Exception
The download has no IP2LOCATION-LITE-DB1.IPV6.CSV.
- OperationCanceledException
cancellationTokenwas canceled.- FormatException
A row has an address that is not a number.