IP geolocation library for Net3000 solutions. Provides IP address lookup services using IP2Location database to retrieve location details including country, region, city, postal code, coordinates, and timezone information.
$ dotnet add package net3000.ipinfoThe net3000.ipinfo library provides IP geolocation services for Net3000 solutions. It uses the IP2Location database (via MaxMind GeoIP2 library) to retrieve detailed location information from IP addresses, including country, region, city, postal code, coordinates, and timezone data.
| Member | Summary | Parameters |
|---|---|---|
Service(string databasePath) | Initializes a new instance of the IP geolocation service. | databasePath (string) - Path to the IP2Location MMDB database file. Defaults to "IP2LOCATION-LITE-DB9.MMDB" |
LocationDetails? GetLocationByIp(string ipAddress) | Gets complete location details for a given IP address. | ipAddress (string) - IP address as string (IPv4 or IPv6) |
string? GetCountryByIp(string ipAddress) | Gets just the country code for an IP address. | ipAddress (string) - IP address as string |
CityCountryInfo? GetCityCountryByIp(string ipAddress) | Gets city and country information for an IP address. | ipAddress (string) - IP address as string |
static bool IsLocalIp(IPAddress ipAddress) | Checks if an IP address is local/private. | ipAddress (IPAddress) - IP address to check |
static bool IsLocalIp(string ipAddress) | Checks if an IP address string is local/private. | ipAddress (string) - IP address string to check |
void Dispose() | Releases resources used by the service. | None |
| Property | Type | Description |
|---|---|---|
IpAddress | string | The IP address that was looked up |
Country | string? | ISO country code (e.g., "US", "CA") |
CountryName | string? | Full country name |
Region | string? | ISO region/subdivision code |
RegionName | string? | Full region/subdivision name |
City | string? | City name |
PostalCode | string? | Postal/ZIP code |
Latitude | double? | Latitude coordinate |
Longitude | double? | Longitude coordinate |
TimeZone | string? | Timezone identifier |
Continent | string? | Continent code |
ContinentName | string? | Full continent name |
| Property | Type | Description |
|---|---|---|
City | string? | City name |
Country | string? | ISO country code |
CountryName | string? | Full country name |
Region | string? | ISO region/subdivision code |
RegionName | string? | Full region/subdivision name |
using net3000.IpInfo;
// Initialize the service with default database path
using var ipService = new Service();
// Get complete location details
var location = ipService.GetLocationByIp("8.8.8.8");
if (location != null)
{
Console.WriteLine($"Country: {location.CountryName} ({location.Country})");
Console.WriteLine($"City: {location.City}");
Console.WriteLine($"Coordinates: {location.Latitude}, {location.Longitude}");
}
// Get just country code
var country = ipService.GetCountryByIp("8.8.8.8");
// Get city and country info
var cityCountry = ipService.GetCityCountryByIp("8.8.8.8");
// Use a custom database file path
using var ipService = new Service("path/to/your/database.mmdb");
// Check if an IP is local/private
bool isLocal = Service.IsLocalIp("192.168.1.1"); // Returns true
bool isPublic = Service.IsLocalIp("8.8.8.8"); // Returns false
This library uses the IP2Location LITE database (MMDB format) which is provided free of charge. The database file (IP2LOCATION-LITE-DB9.MMDB) should be included in your project and copied to the output directory.
Note: The IP2Location LITE edition has accuracy up to Class C (192.168.1.X) only. For higher accuracy, you can acquire commercial editions from IP2Location.com.
This library is proprietary to Net3000. The IP2Location LITE database is provided under the IP2Location LITE license terms. See LICENSE.md for details.
This library uses the IP2Location LITE database for IP geolocation. All sites, advertising materials, and documentation mentioning features or the use of this database must display the following acknowledgment:
"[Your site name or product name] uses the IP2Location LITE database for IP geolocation."