Example #1
0
        private List<ResearchModel> checkInGeo(List<CsvStructure> list)
        {
            GeoApiResponse geoResponse;
            ResearchModel temp = new ResearchModel();
            GeoApiResponse userDetails = ConnectionUtils.GetInstance().UserDetailsFromGeoApi();
            List<ResearchModel> reasearchResult = new List<ResearchModel>();
            int iterator = 1;
            foreach (CsvStructure record in list)
            {
                System.Threading.Thread.Sleep(1000);
                //First find domain IP address
                geoResponse = ConnectionUtils.GetInstance().HostDetailsFromGeoApi(record.URL);
                Console.WriteLine(iterator++ + " "+ record.URL+ " " +geoResponse );
                if (geoResponse != null)
                {
                    temp = new ResearchModel();
                    temp.IPAddress = geoResponse.query;
                    temp.DomainName = record.URL;
                    temp.Latitude = geoResponse.lat.ToString();
                    temp.Longitude = geoResponse.lon.ToString();
                    temp.DistanceTo = ConnectionUtils.GetInstance().GetDistanceBetweenGeographicPoints(userDetails.lat, userDetails.lon, geoResponse.lat, geoResponse.lon).ToString();

                    reasearchResult.Add(temp);
                }
            }
            return reasearchResult;
        }
Example #2
0
        private void MakeResearch(List<CsvStructure> list)
        {
            ConnectionUtils utils = ConnectionUtils.GetInstance();
            List<ResearchModel> reasearchResult = new List<ResearchModel>();
            ResearchModel temp = new ResearchModel();
            float distance = 0;
            GeoApiResponse geoResponse;
            PingReply tempReply;
            GeoApiResponse userDetails = utils.UserDetailsFromGeoApi();
            PingReply smallReply;
            PingReply biggerReply;
            PingReply[] ttl;
            foreach (CsvStructure record in list)
            {
                //First find domain IP address
                geoResponse = utils.HostDetailsFromGeoApi(record.URL);

                if (geoResponse != null)
                {
                    //This will be same for all 10 results
                    temp = new ResearchModel();
                    temp.IPAddress = geoResponse.query;
                    temp.DomainName = record.URL;
                    temp.Latitude = geoResponse.lat.ToString();
                    temp.Longitude = geoResponse.lon.ToString();
                    temp.DistanceTo = utils.GetDistanceBetweenGeographicPoints(userDetails.lat, userDetails.lon, geoResponse.lat, geoResponse.lon).ToString();
                    try
                    {
                        ttl = utils.PerformPathping(IPAddress.Parse(geoResponse.query));
                    }
                    catch (System.FormatException e)
                    {
                        break;
                    }
                    if (ttl == null)
                        temp.TTL = "error";
                    else
                    { temp.TTL = ttl.Length.ToString(); }

                    for (int i = 0; i < 10; i++)//10 measures for each domain
                    {
                        smallReply = utils.PingHost(IPAddress.Parse(geoResponse.query), true);
                        if (smallReply != null)
                            temp.Time8B = smallReply.RoundtripTime.ToString();
                        else
                            temp.Time8B = "-1";

                        biggerReply = utils.PingHost(IPAddress.Parse(geoResponse.query), false);
                        if (biggerReply != null)
                            temp.Time64kB = biggerReply.RoundtripTime.ToString();
                        else
                            temp.Time64kB = "-1";

                        reasearchResult.Add(temp);
                    }
                }

            }
            writeToFile(reasearchResult);
        }
Example #3
0
        private List<ResearchModel> checkPing(List<ResearchModel> toCheck)
        {
            PingReply smallReply;
            PingReply biggerReply;
            List<ResearchModel> finalList = new List<ResearchModel>();
            ResearchModel temp = new ResearchModel();
            PingReply[] ttl;
            foreach (ResearchModel record in toCheck)
            {
                temp = record;
                if (false) // 8byte and ttl
                {
                    try
                    {
                        ttl = ConnectionUtils.GetInstance().PerformPathping(IPAddress.Parse(record.IPAddress));
                    }
                    catch (System.FormatException e)
                    {
                        continue;
                    }
                    if (ttl == null)
                        continue;
                    else
                    {
                        temp.TTL = ttl.Length.ToString();
                    }

                    smallReply = ConnectionUtils.GetInstance().PingHost(IPAddress.Parse(record.IPAddress), true);
                    if (smallReply != null)
                        temp.Time8B = smallReply.RoundtripTime.ToString();
                    else
                        continue;
                }
                if (false) // 1 kB
                {
                    biggerReply = ConnectionUtils.GetInstance().PingHost(IPAddress.Parse(record.IPAddress), false);
                    if (biggerReply != null)
                        temp.Time64kB = biggerReply.RoundtripTime.ToString();
                    else
                        continue;
                }
                if (true)
                {
                    long pingTotal = 0;
                    int howManyMeasures = 0;
                    for (int i = 0; i < 10; i++)
                    {
                        smallReply = ConnectionUtils.GetInstance().PingHost(IPAddress.Parse(record.IPAddress), false);
                        if (smallReply != null)
                        {
                            howManyMeasures++;
                            pingTotal += smallReply.RoundtripTime;
                        }
                    }
                    temp.Time64kB = (pingTotal / howManyMeasures).ToString();
                }
                finalList.Add(temp);
            }
            return finalList;
        }