예제 #1
0
        /// <summary>
        /// The main entry-point to the application.
        /// </summary>
        internal static void Main()
        {
            var client = new FreeGeoIPClient();

            string hostNameOrIPAddress = null;

            while (true)
            {
                Console.Write("Host name or IP address: ");
                hostNameOrIPAddress = Console.ReadLine();

                if (string.IsNullOrEmpty(hostNameOrIPAddress))
                {
                    break;
                }

                IPLookup result;

                try
                {
                    result = client.LookupAsync(hostNameOrIPAddress).Result;
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine();
                    Console.Error.WriteLine("Failed to look up IP address: {0}", ex.ToString());
                    continue;
                }

                Console.WriteLine();
                Console.WriteLine("Result for {0}:", hostNameOrIPAddress);
                Console.WriteLine();

                if (result == null)
                {
                    Console.WriteLine("  Not found.");
                }
                else
                {
                    Console.WriteLine("   IP address: {0}", result.IPAddress);
                    Console.WriteLine("     Lat/Long: {0:N2},{1:N2}", result.Latitude, result.Longitude);
                    Console.WriteLine("         City: {0}", result.City);
                    Console.WriteLine("  Postal Code: {0}", result.PostalCode);
                    Console.WriteLine("       Region: {0}", result.RegionCode);
                    Console.WriteLine("      Country: {0}", result.CountryCode);
                    Console.WriteLine("    Time Zone: {0}", result.TimeZone);
                }

                Console.WriteLine();
            }
        }
예제 #2
0
        public async Task CreateAnonChat(string name, string email, string phone, string url)
        {
            FreeGeoIPClient ipClient = new FreeGeoIPClient();
            var             ip       = _accessor.HttpContext?.Connection?.RemoteIpAddress?.ToString();
            var             usr      = new AnonymousUser()
            {
                connectionID = Context.ConnectionId, IP = ip, Name = name, Phone = phone, Email = email, LastActiveTime = DateTime.Now, isActive = true, Site = url
            };

            try
            {
                FreeGeoIPCore.Models.Location location = ipClient.GetLocation(ip).Result;
                usr.country = location.CountryName;
                usr.city    = location.City;
            }
            catch (Exception e)
            {
            }
            finally
            {
                usr.country = "-";
                usr.city    = "-";
            }
            _dbContext.anonusers.Add(usr);

            _dbContext.SaveChanges();

            var loggedinUsers = _dbContext.singleActiveUsers.ToList();

            foreach (var loggeduser in loggedinUsers)
            {
                await Groups.AddToGroupAsync(loggeduser.ConnectionID, usr.ID);

                var newgrp = new grouplistresponse {
                    city = usr.city, country = usr.country, anonid = usr.ID, IP = ip, name = usr.Name, newMessageseen = usr.seenByUser, lastTime = TimeAgo(usr.LastActiveTime), active = usr.isActive, email = usr.Email, phone = usr.Phone, site = usr.Site
                };
                await Clients.Client(loggeduser.ConnectionID).SendAsync("newGroup", Newtonsoft.Json.JsonConvert.SerializeObject(newgrp));
            }
            _dbContext.SaveChanges();
            await Clients.Caller.SendAsync("myid", usr.connectionID, true);

            await Groups.AddToGroupAsync(Context.ConnectionId, usr.ID);
        }
        public IActionResult Index(double lon, double lat)
        {
            FreeGeoIPClient clientIP = new FreeGeoIPClient();

            string ipAdd = WeatherGeolocation.GetIPRequest(_httpConAccessor);

            FreeGeoIPCore.Models.Location location = clientIP.GetLocation(ipAdd).Result;

            GeoCoordinate geoCoordinate = new GeoCoordinate();

            if (lon == 0 && lat == 0)
            {
                geoCoordinate.Longitude = location.Longitude;
                geoCoordinate.Latitude  = location.Latitude;
            }
            else
            {
                geoCoordinate.Longitude = lon;
                geoCoordinate.Latitude  = lat;
            }
            return(View());
        }