示例#1
0
文件: Program.cs 项目: veysel/Tremone
        static void Main(string[] args)
        {
            try
            {
                string GetIpUrl   = "https://api.ipify.org/?format=json";
                string GetInfoUrl = "http://ip-api.com/json/";

                using (HttpClient client = new HttpClient())
                {
                    string      hostName  = Dns.GetHostName();
                    string      ipAddress = JsonConvert.DeserializeObject <IpModel>(client.GetStringAsync(GetIpUrl).Result).Ip;
                    IpInfoModel infoModel = JsonConvert.DeserializeObject <IpInfoModel>(client.GetStringAsync(GetInfoUrl + ipAddress).Result);

                    Console.WriteLine($"Host : { hostName }");
                    Console.WriteLine($"Ip : { ipAddress }");
                    Console.WriteLine($"City : { infoModel.City }");
                    Console.WriteLine($"Country : { infoModel.Country }");
                    Console.WriteLine($"Isp : { infoModel.Isp }");
                    Console.WriteLine($"Lat Lon : { infoModel.Lat } , { infoModel.Lon }");
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine($"Error : {exp.Message}");
            }

            Console.ReadLine();
        }
示例#2
0
        public void WriteLog(string message)
        {
            try
            {
                string GetIpUrl    = ConfigurationManager.AppSettings["GetIpUrl"].ToString();
                string GetInfoUrl  = ConfigurationManager.AppSettings["GetInfoUrl"].ToString();
                string PutLogUrl   = ConfigurationManager.AppSettings["PutLogUrl"].ToString();
                string ProjectName = ConfigurationManager.AppSettings["ProjectName"].ToString();

                using (HttpClient client = new HttpClient())
                {
                    LogModel model = new LogModel();

                    model.LogTime    = DateTime.Now;
                    model.LogName    = ProjectName;
                    model.LogContent = message;
                    model.HostName   = Dns.GetHostName();

                    model.LocalIpAddress.AddRange(Dns.GetHostEntry(Dns.GetHostName()).AddressList.Select(item => item.ToString()));

                    model.IpAddress = JsonConvert.DeserializeObject <IpModel>(client.GetStringAsync(GetIpUrl).Result).Ip;

                    IpInfoModel tempModel = JsonConvert.DeserializeObject <IpInfoModel>(client.GetStringAsync(GetInfoUrl + model.IpAddress).Result);

                    // This is Spaghetti :|
                    model.City    = tempModel.City;
                    model.Country = tempModel.Country;
                    model.Isp     = tempModel.Isp;
                    model.Lat     = tempModel.Lat;
                    model.Lon     = tempModel.Lon;

                    // Put Log Model Info
                    StringContent content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
                    client.PutAsync(PutLogUrl, content);

                    // For Surprise Egg :)
                    System.Threading.Thread.Sleep(2 * 1000);

                    // Disabled For Öylesine :)
                    //LogManager.GetCurrentClassLogger().Info("Success");
                }
            }
            catch (Exception exp)
            {
                //TODO : Singleton Pattern To Do
                //This is a slow-running method.
                LogManager.GetCurrentClassLogger().Error($"Error Message : {exp.Message}");
            }
        }
        public string JsonParse(string jsonRes)
        {
            // Console.WriteLine(jsonRes);

            string ipinfoRes = "";

            //Console.WriteLine(ipifo.code);
            if (!string.IsNullOrEmpty(jsonRes))
            {
                IpInfoModel ipinfo = JsonConvert.DeserializeObject <IpInfoModel>(jsonRes);
                ipinfoRes = string.Format(" Area:{0}  Local:{1}", ipinfo.data.cuntry, ipinfo.data.local);
                return(ipinfoRes);
            }
            else
            {
                return(ConstModel.PROMPT_RETRY);
            }
        }
示例#4
0
        public async Task <IpInfoModel> GetAllIpInfo(ServerSelection servers)
        {
            Task <GeolocationModel> geolocationTask = Task.Factory.StartNew <GeolocationModel>(() => {
                if (servers.Servers == null || servers.Servers.Contains("geolocation"))
                {
                    GeoIpService geoService = new GeoIpService(_client);
                    return(geoService.RequestGeoInfoAsync(servers.Ip).Result);
                }
                else
                {
                    return(null);
                }
            });

            Task <VirusTotalModel> virusTotalTask = Task.Factory.StartNew <VirusTotalModel>(() => {
                if (servers.Servers == null || servers.Servers.Contains("virustotal"))
                {
                    VirusTotalService virusTotalService = new VirusTotalService(_client);
                    return(virusTotalService.RequestVirusInfoAsync(servers.Ip).Result);
                }
                else
                {
                    return(null);
                }
            });


            await Task.WhenAll(geolocationTask, virusTotalTask);

            IpInfoModel results = new IpInfoModel();

            results.LocationInfo = await geolocationTask;

            results.VirusTotal = await virusTotalTask;

            return(results);
        }