Exemplo n.º 1
0
        private async Task <ip_address> _Query(string ip)
        {
            CityResponse cityResponse;

            await saveSlim.WaitAsync();

            try {
                var cached_ip = await db.ip_addresses.FirstOrDefaultAsync(a => a.ip == ip);

                if (cached_ip != null)
                {
                    return(cached_ip);
                }
            }
            finally {
                saveSlim.Release();
            }

            await maxConcurrent.WaitAsync();

            try {
                cityResponse = await geoIpClient.CityAsync(ip);
            }
            finally {
                maxConcurrent.Release();
            }

            await saveSlim.WaitAsync();

            try {
                var ip_address = new ip_address()
                {
                    ip              = cityResponse.Traits.IPAddress,
                    city_name       = cityResponse.City?.Name,
                    connection_type = cityResponse.Traits?.ConnectionType,
                    isp             = cityResponse.Traits?.Isp,
                    country_code    = cityResponse.Country.IsoCode,
                    country_name    = cityResponse.Country.Name,
                    organisation    = cityResponse.Traits.Organization,
                    latitude        = cityResponse.Location.Latitude,
                    longitude       = cityResponse.Location.Longitude
                };

                db.ip_addresses.Add(ip_address);

                await db.SaveChangesAsync();

                return(ip_address);
            }
            finally {
                saveSlim.Release();
            }
        }
Exemplo n.º 2
0
        public bool check_ip()
        {
            bool     enable_access = false;
            database _database_    = new database();

            _database_.open_connection();
            ip_address address = new ip_address();

            enable_access = address.check_ip(_database_, address);
            _database_.close_connection();
            return(enable_access);
        }