Beispiel #1
0
        public IPInformation Get(string address)
        {
            using (var client = new WebServiceClient(119543, "1Ksa6iuvfOJu"))
            {
                try
                {
                    var response = client.CityAsync(address).Result;

                    return(new IPInformation
                    {
                        Latitude = response.Location.Latitude,
                        Longitude = response.Location.Longitude,
                        Isp = response.Traits.Isp,
                        IPAddress = response.Traits.IPAddress,
                        City = response.City.Name,
                        Country = response.Country.Name,
                        Postal = response.Postal.Code
                    });
                }
                catch
                {
                    return(new IPInformation
                    {
                        IPAddress = address
                    });
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            using (var client = new WebServiceClient(119543, "1Ksa6iuvfOJu"))
            {
                // Do the lookup
                var response = client.CityAsync("71.197.137.82").Result;

                Console.WriteLine(response.Location);
            }
        }
        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();
            }
        }