Beispiel #1
0
        public NGeoClientTest()
        {
            nGeoRequest = new Request()
            {
                Format = Format.Json,
                IP = HelperTest.GetLocalIP()
            };

            nGeoClient = new NGeoClient(nGeoRequest);

            rawData = nGeoClient.Execute();
        }
Beispiel #2
0
        public NGeoClientTest()
        {
            nGeoRequest = new Request()
            {
                Format = Format.Json,
                IP     = HelperTest.GetLocalIP()
            };

            nGeoClient = new NGeoClient(nGeoRequest);

            rawData = nGeoClient.Execute();
        }
Beispiel #3
0
        public static AjaxCallResult GuessCountry()
        {
            // IMPORTANT: If you're implementing a sensitive organization, this should use YOUR OWN geoip server and not freegeoip.com, which
            // may potentially be eavesdroppable. Look at the freegeoip.com for how to download their database.

            if (HttpContext.Current.Request.UserHostAddress == "::1" && !Debugger.IsAttached)
            {
                // yeah, we're running from localhost, no big point trying to geoip this
                return(new AjaxCallResult {
                    Success = false
                });
            }

            try
            {
                string ipAddress = Logic.Support.SupportFunctions.GetMostLikelyRemoteIPAddress();

                NGeoIP.RawData rawData = (NGeoIP.RawData)GuidCache.Get(ipAddress);

                Persistence.Key["DebugData"] = HttpContext.Current.Request.ToRaw();

                if (rawData == null)
                {
                    NGeoIP.Request request = new Request()
                    {
                        Format = Format.Json,
                        IP     = ipAddress
                    };
                    NGeoClient client = new NGeoClient(request);
                    rawData = client.Execute();
                }

                if (!string.IsNullOrEmpty(rawData.CountryCode))
                {
                    // Successful lookup

                    GuidCache.Set(ipAddress, rawData);  // store lookup results in cache for later

                    return(new AjaxCallResult {
                        Success = true, DisplayMessage = rawData.CountryCode
                    });
                }
            }
            catch (Exception)
            {
                // We failed, return failure in the statement following this block
            }

            return(new AjaxCallResult {
                Success = false
            });
        }
Beispiel #4
0
        public static string Lookup(string ip)
        {
            NGeoIP.Request request = new Request()
            {
                Format = Format.Json,
                IP     = HttpContext.Current.Request.UserHostAddress
            };
            NGeoClient client = new NGeoClient(request);

            NGeoIP.RawData rawData = client.Execute();

            return(rawData.CountryCode);
        }
        public static string RetrieveCountryId(string ip)
        {
            try
            {
                var nGeoRequest = new Request
                {
                    Format = Format.Json,
                    IP = ip
                };

                var nGeoClient = new NGeoClient(nGeoRequest);

                var rawData = nGeoClient.Execute();

                return rawData.CountryCode;
            }
            catch (Exception)
            {
                return null;
            }
        }
Beispiel #6
0
        private void ProcessaInfo(Bot.Types.Message message, out bool respondeu, String command)
        {
            var info     = new StringBuilder();
            var ipAdress = String.Empty;

            if (command.StartsWith(INFOFULL))
            {
                ipAdress = getIPAdress();
            }

            var computerInfo = new Microsoft.VisualBasic.Devices.ComputerInfo();

            info.Append("Nome da máquina: ");
            info.AppendLine(Environment.MachineName);
            info.Append("Processador: ");
            info.AppendLine(getProcessorName());
            info.Append("Memória RAM total: ");
            info.AppendLine(computerInfo.TotalPhysicalMemory / 1024000 + " MB");
            info.Append("Memória RAM disponível: ");
            info.AppendLine(computerInfo.AvailablePhysicalMemory / 1024000 + " MB");
            info.AppendLine("Discos: ");
            foreach (var item in getDriveInfo())
            {
                info.Append("Nome: ");
                info.AppendLine(item.Name);

                if (item.DriveFormat != null)
                {
                    info.Append("Formato: ");
                    info.AppendLine(item.DriveFormat);
                }

                if (item.DriveType != null)
                {
                    info.Append("Tipo: ");
                    info.AppendLine(item.DriveType);
                }

                info.AppendLine("Tamanho total: ");
                info.AppendLine(item.TotalSpace);
                info.AppendLine("Espaço livre: ");
                info.AppendLine(item.FreeSpace);
            }

            info.Append("Usuário logado: ");
            info.AppendLine(Environment.UserName);
            info.AppendLine("Versão do Windows: ");
            info.Append(computerInfo.OSFullName + " ");
            info.AppendLine(Environment.Is64BitOperatingSystem ? " | 64 bits" : String.Empty);
            info.Append("Processadores: ");
            info.AppendLine(Environment.ProcessorCount.ToString());
            info.AppendLine("Diretório do sistema: ");
            info.AppendLine(Environment.SystemDirectory);

            if (!String.IsNullOrEmpty(ipAdress))
            {
                info.AppendLine("Endereço IP: " + ipAdress);
            }

            try
            {
                if (!String.IsNullOrEmpty(ipAdress))
                {
                    var nGeoRequest = new Request()
                    {
                        Format = Format.Json,
                        IP     = ipAdress
                    };

                    var nGeoClient = new NGeoClient(nGeoRequest);

                    var rawData = nGeoClient.Execute();

                    info.Append("País: ");
                    info.AppendLine(rawData.CountryCode + "|" + rawData.CountryName);
                    info.Append("Cidade: ");
                    info.AppendLine(rawData.City);
                }
            }
            catch (Exception)
            {
                info.AppendLine("Não foi possível obter a geolocalização do IP");
                lockedExecution = false;
            }

            var msg = bot.SendTextMessageAsync(Convert.ToInt32(message.Chat.Id), info.ToString()).Result;

            respondeu       = true;
            lockedExecution = false;
            return;
        }