Example #1
0
        public static List <string> GetIpLocationList(List <string> ipAddresses)
        {
            List <string> locationList = new List <string>();
            int           index        = 0;

            foreach (var address in ipAddresses)
            {
                if (!string.IsNullOrEmpty(address))
                {
                    string result = IPLocationUtil.GetIPLocation(address);
                    locationList.Add(result);
                }
                else
                {
                    locationList.Add(string.Empty);
                }
                index++;
                if (index % 500 == 0)
                {
                    Console.WriteLine(index);
                }
                Thread.Sleep(30);
            }
            return(locationList);
        }
Example #2
0
        public static void GetIpLocationList(Workbook workbook, string filePath)
        {
            Worksheet sheet = workbook.Worksheets[0];

            List <string> locationList       = new List <string>();
            Dictionary <string, string> dict = new Dictionary <string, string>();

            int rowIndex = 1;

            while (sheet.Cells[rowIndex, 2].Value != null)
            {
                string ipaddress = sheet.Cells[rowIndex, 1].StringValue;
                if (string.IsNullOrEmpty(sheet.Cells[rowIndex, 0].StringValue.Trim()))
                {
                    string result = string.Empty;
                    if (dict.ContainsKey(ipaddress))
                    {
                        result = dict[ipaddress];
                    }
                    else
                    {
                        result = IPLocationUtil.GetIPLocation(ipaddress);
                        dict.Add(ipaddress, result);
                    }

                    sheet.Cells[rowIndex, 0].PutValue(result);
                    if (rowIndex % 10 == 0)
                    {
                        workbook.Save(filePath);
                    }
                    Console.WriteLine(rowIndex);
                    Thread.Sleep(50);
                }
                rowIndex++;
            }
            workbook.Save(filePath);
        }