Table of Contents

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

csvStream Stream

IP2Location's CSV; it is closed after.

outputFile string

The file to write; an existing one is overwritten.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Exceptions

OperationCanceledException

cancellationToken was 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

csvStream Stream

IP2Location's CSV; it is closed after.

outputZipFile string

The zip file to write; an existing one is overwritten.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Exceptions

OperationCanceledException

cancellationToken was 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

ipLocationsCsvStream Stream

IP2Location's CSV; it is closed after.

cancellationToken CancellationToken

The 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

cancellationToken was 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

filePath string

The database file to write.

apiKey string

The IP2Location download token.

forIpRange bool

true to build the zip LocalIpRangeLocationProvider reads; false for the file Deserialize(Stream, string?) reads.

interval TimeSpan?

How old the file may be before it is rebuilt, or null for 7 days.

cancellationToken CancellationToken

The 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

cancellationToken was canceled.

FormatException

A row has an address that is not a number.