static void AccountInfo() { CensysDataRepository repo = new CensysDataRepository(); var accounts = repo.GetAllCensysAccounts().Result; foreach (var account in accounts) { CensysApiServicee service = new CensysApiServicee(account.API_ID, account.Secret); var data = service.GetAccountData().Result; System.Console.WriteLine(data); } }
static void InsertDataToDb() { IPinfo ipInfo = new IPinfo("Files/suip.ipranges"); var ipRangeList = ipInfo.GetIpAddresses(); CensysDataRepository repo = new CensysDataRepository(); // var tasks = new List<Task>(); int totalCount = ipRangeList.Count; System.Console.WriteLine(totalCount); var accounts = repo.GetAllCensysAccounts().Result; var accId = 0; for (int j = 0; j < ipRangeList.Count; j++) { var ipRange = ipRangeList[j]; var account = accounts[accId]; CensysApiServicee service = new CensysApiServicee(account.API_ID, account.Secret); // Task task = Task.Run( async () => // { // var data = await service.GetJsonSearchData(IndexEnum.ipv4, new CensysSearchPost() // { // query = ipRange // }); // requestedData.Add(data); // System.Console.WriteLine("Passed-" + requestedData.Count); // }); // tasks.Add(task); var data = service.GetJsonSearchData(IndexEnum.ipv4, new CensysSearchPost() { query = $"ip:{ipRange}" }).Result; repo.InsertRangeWithJsonData(new CensysData() { Data = data.Json, StatusCode = data.ResponseStatusCode, Message = data.ResponseMessage, IpRange = new IpRange() { Range = data.IpRange } }); var prcent = ((j * 100) / totalCount); System.Console.WriteLine("Passed - " + prcent + j); if (j % 120 == 0 && j != 0 || data.ResponseStatusCode == "TooManyRequests") { System.Console.WriteLine("Account Changed"); accId++; } } // Task.WaitAll(tasks.ToArray()); // repo.BulkInsertRangeWithJsonData(requestedData.Select(s => new CensysData() // { // Data = s.Json, // StatusCode = s.ResponseStatusCode, // Message = s.ResponseMessage, // IpRange = new IpRange() // { // Range = s.IpRange // } // }).ToList()); }