/// <summary> /// Event for search link found. /// </summary> /// <param name="ip"></param> /// <param name="bingSearcher"></param> /// <param name="currentResults"></param> private void SerchLinkWebBingEvent(string ip, BingWebSearcher bingSearcher, List <string> currentResults) { bingSearcher.SearcherLinkFoundEvent += delegate(object sender, EventsThreads.ThreadListDataFoundEventArgs e) { var op = Partitioner.Create(e.Data); var po = new ParallelOptions(); if (Program.cfgCurrent.ParallelDnsQueries != 0) { po.MaxDegreeOfParallelism = Program.cfgCurrent.ParallelDnsQueries; } Parallel.ForEach(op, po, delegate(object item, ParallelLoopState loopState) { if (CheckToSkip()) { loopState.Stop(); } try { var url = new Uri((string)item); if (currentResults.Any(d => d.ToLower() == url.Host.ToLower())) { return; } currentResults.Add(url.Host); var isInBaseDomain = false; try { if (Dns.GetHostAddresses(url.Host).Any(IP => IP.ToString() == ip)) { isInBaseDomain = true; } } catch { } if (!isInBaseDomain) { return; } var source = $"{Program.data.GetIpSource(ip)} > Bing IP Search [{url.Host}]"; Program.data.AddResolution(url.Host, ip, source, MaxRecursion, Program.cfgCurrent, true); Program.LogThis(new Log(Log.ModuleType.IPBingSearch, $"[{PanelSearchIPBing.EngineToString(searchIPEngine)}] Found domain {url.Host} in IP {ip}", Log.LogType.medium)); } catch { } } ); }; bingSearcher.SearcherLogEvent += IpBingSearcherLogEvent; bingSearcher.GetCustomLinks($"ip:{ip}"); bingSearcher.Join(); }
/// <summary> /// Search an IP address in Bing /// </summary> /// <param name="ip"></param> /// <returns></returns> public bool SearchIpBingSingleIp(string ip) { if (CheckToSkip()) { EnableSkip("Skip to next IP"); return(false); } if (ip.Contains("\\") || ip.Contains("/") || !DNSUtil.IsIPv4(ip)) { return(false); } var message = $"[{PanelSearchIPBing.EngineToString(searchIPEngine)}] Searching domains in IP {ip}"; Program.LogThis(new Log(Log.ModuleType.IPBingSearch, message, Log.LogType.debug)); Program.ChangeStatus(message); List <string> currentResults; switch (searchIPEngine) { case PanelSearchIPBing.Engine.BingWeb: try { var bingSearcher = new BingWebSearcher { LocatedInRegion = BingWebSearcher.Region.AnyRegion, SearchAll = true, WriteInLanguage = BingWebSearcher.Language.AnyLanguage }; currentResults = new List <string>(); SerchLinkWebBingEvent(ip, bingSearcher, currentResults); break; } catch { break; } case PanelSearchIPBing.Engine.BingAPI: var bingSearcherApi = new BingAPISearcher(Program.cfgCurrent.BingApiKey); currentResults = new List <string>(); SerchLinkApiBingEvent(ip, bingSearcherApi, currentResults); break; } return(true); }
private void SerchLinkApiBingEvent(string ip, BingAPISearcher bingSearcherApi, List <string> currentResults) { bingSearcherApi.SearcherLinkFoundEvent += delegate(object sender, EventsThreads.ThreadListDataFoundEventArgs e) { var op = Partitioner.Create(e.Data); var po = new ParallelOptions(); if (Program.cfgCurrent.ParallelDnsQueries != 0) { po.MaxDegreeOfParallelism = Program.cfgCurrent.ParallelDnsQueries; } Parallel.ForEach(op, po, delegate(object item, ParallelLoopState loopState) { if (CheckToSkip()) { loopState.Stop(); } try { var br = (BingApiResult)item; var url = new Uri(br.Url); if ( currentResults.Any(d => string.Equals(d, url.Host, StringComparison.CurrentCultureIgnoreCase))) { return; } currentResults.Add(url.Host); var source = $"{Program.data.GetIpSource(ip)} > Bing IP Search [{url.Host}]"; Program.data.AddResolution(url.Host, ip, source, MaxRecursion, Program.cfgCurrent, true); Program.LogThis(new Log(Log.ModuleType.IPBingSearch, $"[{PanelSearchIPBing.EngineToString(searchIPEngine)}] Found domain {url.Host} in IP {ip}", Log.LogType.medium)); } catch { } } ); }; bingSearcherApi.SearcherLogEvent += IpBingSearcherLogEvent; bingSearcherApi.GetCustomLinks($"ip:{ip}"); bingSearcherApi.Join(); }
/// <summary> /// Search an IP address in Bing /// </summary> /// <param name="ip"></param> /// <returns></returns> public bool SearchIpBingSingleIp(string ip) { CancelIfSkipRequested(); if (ip.Contains("\\") || ip.Contains("/") || !DNSUtil.IsIPv4(ip)) { return(false); } var message = $"[{PanelSearchIPBing.EngineToString(searchIPEngine)}] Searching domains in IP {ip}"; Program.LogThis(new Log(Log.ModuleType.IPBingSearch, message, Log.LogType.debug)); Program.ChangeStatus(message); LinkSearcher searcher = null; try { switch (searchIPEngine) { case PanelSearchIPBing.Engine.BingWeb: searcher = new BingWebSearcher { LocatedInRegion = BingWebSearcher.Region.AnyRegion, WriteInLanguage = BingWebSearcher.Language.AnyLanguage }; break; case PanelSearchIPBing.Engine.BingAPI: searcher = new BingAPISearcher(Program.cfgCurrent.BingApiKey); break; } SearchIP(ip, searcher); } catch (Exception) { return(false); } return(true); }
private void SearchIP(string ip, LinkSearcher searcher) { ConcurrentBag <string> domainsFound = new ConcurrentBag <string>(); searcher.ItemsFoundEvent += delegate(object sender, EventsThreads.CollectionFound <Uri> e) { var op = Partitioner.Create(e.Data); var po = new ParallelOptions(); if (Program.cfgCurrent.ParallelDnsQueries != 0) { po.MaxDegreeOfParallelism = Program.cfgCurrent.ParallelDnsQueries; } try { Parallel.ForEach(op, po, delegate(Uri url, ParallelLoopState loopState) { CancelIfSkipRequested(); try { if (domainsFound.Any(d => d.ToLower() == url.Host.ToLower())) { return; } domainsFound.Add(url.Host); bool isInBaseDomain = false; try { if (Dns.GetHostAddresses(url.Host).Any(IP => IP.ToString() == ip)) { isInBaseDomain = true; } } catch { } if (!isInBaseDomain) { return; } string source = $"{Program.data.GetIpSource(ip)} > {searcher.Name} [{url.Host}]"; Program.data.AddResolution(url.Host, ip, source, MaxRecursion, Program.cfgCurrent, true); Program.LogThis(new Log(Log.ModuleType.IPBingSearch, $"[{PanelSearchIPBing.EngineToString(searchIPEngine)}] Found domain {url.Host} in IP {ip}", Log.LogType.medium)); } catch { } }); } catch (AggregateException) { } }; searcher.SearcherLogEvent += IpBingSearcherLogEvent; searcher.CustomSearch(this.searchCancelToken, $"ip:{ip}") .ContinueWith((e) => SearchEngineFinish(e, searcher.Name, Log.ModuleType.IPBingSearch)) .Wait(); }