/// <summary> /// Performs a GeoIP lookup on an IPv4 or IPv6 address and returns the <see cref="Country" /> object as the result. If the IP address lookup failed, <see langword="null" /> is returned. /// </summary> /// <param name="ipAddress">An <see cref="IPAddress" /> object to perform the lookup on.</param> /// <returns> /// The <see cref="Country" /> object as the result, or <see langword="null" />, if the IP address lookup failed. /// </returns> public static Country Lookup(IPAddress ipAddress) { Check.ArgumentNull(ipAddress, nameof(ipAddress)); if (GeoIPHelper.TryConvertIPv4(ipAddress, out uint address)) { foreach (IPRange range in Ranges) { if (address >= range.From && address <= range.To) { return(range.Country); } } } else if (GeoIPHelper.TryConvertIPv6(ipAddress, out byte[] addressBytes))
/// <summary> /// Performs a GeoIP city lookup on an IPv4 or IPv6 address and returns the <see cref="CityLookupResult" /> object as the result. If the IP address lookup failed, <see langword="null" /> is returned. /// </summary> /// <param name="ipAddress">An <see cref="IPAddress" /> object to perform the lookup on.</param> /// <returns> /// The <see cref="CityLookupResult" /> object as the result, or <see langword="null" />, if the IP address lookup failed. /// </returns> public static CityLookupResult Lookup(IPAddress ipAddress) { Check.ArgumentNull(ipAddress, nameof(ipAddress)); if (GeoIPHelper.TryConvertIPv4(ipAddress, out uint address)) { foreach (CityRange range in Ranges) { if (address >= range.From && address <= range.To) { return(new CityLookupResult(range.City, range.PostalCode, range.Latitude, range.Longitude, range.AccuracyRadius)); } } } else if (GeoIPHelper.TryConvertIPv6(ipAddress, out byte[] addressBytes))