/// <summary>
    /// Returns current distance (in kilometers) from specified location (based on Geo IP).
    /// </summary>
    /// <param name="parameters">
    /// Latitude of the place;
    /// Longitude of the place;
    /// </param>
    public static object GetCurrentDistance(params object[] parameters)
    {
        if (parameters.Length == 2)
        {
            double lat = ValidationHelper.GetDouble(parameters[0], 0, CultureHelper.EnglishCulture.Name);
            double lon = ValidationHelper.GetDouble(parameters[1], 0, CultureHelper.EnglishCulture.Name);

            return(GeoIPHelper.GetCurrectGeoLocation().Distance(lat, lon));
        }

        throw new NotSupportedException();
    }
Beispiel #2
0
        /// <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))
Beispiel #3
0
        /// <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))