private void btAllLinksBing_Click(object sender, EventArgs e) { domain.map.SearchingAllLinks = HttpMap.SearchStatus.Searching; var wsSearch = new BingWebSearcher { SearchAll = true, Site = domain.Domain }; wsSearch.SearcherLinkFoundEvent += wsSearch_SearcherLinkFoundEvent; wsSearch.SearcherEndEvent += delegate { domain.map.SearchingAllLinks = HttpMap.SearchStatus.Finished; Invoke(new MethodInvoker(delegate { Program.LogThis(new Log(Log.ModuleType.Crawling, "Finishing the links extraction of " + domain.Domain, Log.LogType.debug)); Program.FormMainInstance.UpdateBottomPanel(domain); })); }; wsSearch.GetCustomLinks("site:" + domain.Domain); Program.LogThis(new Log(Log.ModuleType.Crawling, "Extracting links of " + domain.Domain, Log.LogType.debug)); AddLog("Bing crawling"); }
/// <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> /// Perform web search based on the user's choice /// </summary> private void SearchWeb() { string message = $"Searching subdomains for {strDomain} in {PanelWebSearcherInformation.EngineToString(searchEngine)}"; Program.LogThis(new Log(Log.ModuleType.WebSearch, message, Log.LogType.debug)); Program.ChangeStatus(message); LinkSearcher searcher = null; switch (searchEngine) { case PanelWebSearcherInformation.Engine.GoogleWeb: searcher = new GoogleWebSearcher { cSafeSearch = GoogleWebSearcher.SafeSearch.off, FirstSeen = GoogleWebSearcher.FirstSeenGoogle.AnyTime, LocatedInRegion = GoogleWebSearcher.Region.AnyRegion, WriteInLanguage = GoogleWebSearcher.Language.AnyLanguage }; break; case PanelWebSearcherInformation.Engine.GoogleAPI: searcher = new GoogleAPISearcher(Program.cfgCurrent.GoogleApiKey, Program.cfgCurrent.GoogleApiCx); break; case PanelWebSearcherInformation.Engine.BingWeb: searcher = new BingWebSearcher { LocatedInRegion = BingWebSearcher.Region.AnyRegion, WriteInLanguage = BingWebSearcher.Language.AnyLanguage }; break; case PanelWebSearcherInformation.Engine.BingAPI: searcher = new BingAPISearcher(Program.cfgCurrent.BingApiKey); break; case PanelWebSearcherInformation.Engine.DuckDuckGoWeb: searcher = new DuckduckgoWebSearcher(); break; } try { searcher.ItemsFoundEvent += CaptureSearchResults; searcher.SearcherLogEvent += WebSearcherLogEvent; CancelIfSkipRequested(); searcher.SearchBySite(this.searchCancelToken, strDomain) .ContinueWith((e) => SearchEngineFinish(e, searcher.Name, Log.ModuleType.WebSearch)) .Wait(); } catch (OperationCanceledException) { } }
/// <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); }
/// <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); }
/// <summary> /// Perform the search through Bing Web /// </summary> private void BingWebSearch() { BingWebSearcher bingSearcher = null; try { bingSearcher = new BingWebSearcher { LocatedInRegion = BingWebSearcher.Region.AnyRegion, SearchAll = true, WriteInLanguage = BingWebSearcher.Language.AnyLanguage }; var currentResults = new List <string>(); bingSearcher.SearcherLinkFoundEvent += delegate(object sender, EventsThreads.ThreadListDataFoundEventArgs e) { var searcher = (BingWebSearcher)sender; foreach (var item in e.Data) { if (CheckToSkip()) { searcher.Abort(); } try { var url = new Uri((string)item); var strHost = url.Host; if ( currentResults.All( D => !string.Equals(D, strHost, StringComparison.CurrentCultureIgnoreCase))) { currentResults.Add(strHost); AddAndLogSubdomainDiscover(strHost); } var domain = Program.data.GetDomain(url.Host); domain.map.AddUrl(url.ToString()); } catch { } } }; bingSearcher.SearcherLogEvent += WebSearcherLogEvent; var endReason = EventsThreads.ThreadEndEventArgs.EndReasonEnum.ErrorFound; bingSearcher.SearcherEndEvent += delegate(object o, EventsThreads.ThreadEndEventArgs e) { endReason = e.EndReason; }; var strSearchString = $"site:{strDomain}"; int nroResultados; do { if (CheckToSkip()) { return; } nroResultados = currentResults.Count; bingSearcher.GetCustomLinks(strSearchString); bingSearcher.Join(); CheckEndReason(endReason, currentResults, strSearchString, 49); } while (endReason == EventsThreads.ThreadEndEventArgs.EndReasonEnum.LimitReached && nroResultados != currentResults.Count); } catch (ThreadAbortException) { } finally { bingSearcher?.Abort(); } }
/// <summary> /// Perform web search based on the user's choice /// </summary> private void SearchWeb() { string message = $"Searching subdomains for {strDomain} in {PanelWebSearcherInformation.EngineToString(searchEngine)}"; Program.LogThis(new Log(Log.ModuleType.WebSearch, message, Log.LogType.debug)); Program.ChangeStatus(message); WebSearcher searcher = null; switch (searchEngine) { case PanelWebSearcherInformation.Engine.GoogleWeb: searcher = new GoogleWebSearcher { SearchAll = true, cSafeSearch = GoogleWebSearcher.SafeSearch.off, FirstSeen = GoogleWebSearcher.FirstSeenGoogle.AnyTime, LocatedInRegion = GoogleWebSearcher.Region.AnyRegion, WriteInLanguage = GoogleWebSearcher.Language.AnyLanguage }; break; case PanelWebSearcherInformation.Engine.GoogleAPI: searcher = new GoogleAPISearcher(Program.cfgCurrent.GoogleApiKey, Program.cfgCurrent.GoogleApiCx) { SearchAll = true }; break; case PanelWebSearcherInformation.Engine.BingWeb: searcher = new BingWebSearcher { LocatedInRegion = BingWebSearcher.Region.AnyRegion, SearchAll = true, WriteInLanguage = BingWebSearcher.Language.AnyLanguage }; break; case PanelWebSearcherInformation.Engine.BingAPI: searcher = new BingAPISearcher(Program.cfgCurrent.BingApiKey); break; case PanelWebSearcherInformation.Engine.DuckDuckGoWeb: searcher = new DuckduckgoWebSearcher(); break; } try { searcher.SearcherLinkFoundEvent += CaptureSearchResults; searcher.SearcherLogEvent += WebSearcherLogEvent; string strSearchString = $"site:{strDomain}"; if (CheckToSkip()) { return; } searcher.GetCustomLinks(strSearchString); searcher.Join(); } catch (ThreadAbortException) { } finally { searcher?.Abort(); } }
public async Task <ActionResult> Upload(HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { // Make sure the user selected an image file // TODO: exception thrown if image > 4MB if (!file.ContentType.StartsWith("image")) { TempData["Message"] = "Only image files may be uploaded"; return(RedirectToAction("Index")); } //if (file.ContentLength > 102400) //{ // TempData["Message"] = "Filesize of image is too large. Maximum file size permitted is " + 4 + "KB"; // return RedirectToAction("Index"); //} // Make sure Images Dir exists on local and on deploy server! System.IO.DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/Images")); // Delete all old images var deleteCount = 0; foreach (FileInfo image in di.GetFiles()) { image.Delete(); deleteCount++; } string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/Images"), pic); // holds payloads from api calls var gender = string.Empty; var caption = string.Empty; var age = string.Empty; file.SaveAs(path); Debug.WriteLine("path: " + path); //............................................................. // Computer Vision service API var SubscriptionKey = WebConfigurationManager.AppSettings["SubscriptionKey"]; VisionServiceClient VisionServiceClient = new VisionServiceClient(SubscriptionKey); using (Stream imageFileStream = System.IO.File.OpenRead(path)) { VisualFeature[] visualFeatures = new VisualFeature[] { VisualFeature.Faces, VisualFeature.Description }; // vision payload AnalysisResult analysisResult = await VisionServiceClient.AnalyzeImageAsync(imageFileStream, visualFeatures); if (analysisResult.Faces.Length != 0) { age = analysisResult.Faces[0].Age.ToString(); gender = analysisResult.Faces[0].Gender; } else { age = "unknown"; gender = "unknown"; } // Assume: there is always a caption caption = analysisResult.Description.Captions[0].Text; //List<string> tags = new List<string>(); //ViewBag.Tags = "Tags : "; //for (int i = 0; i < analysisResult.Description.Tags.Length; i++) //{ // ViewBag.Tags += analysisResult.Description.Tags[i] + " "; //} ViewBag.ImagePath = "..\\Images\\" + pic; ViewBag.Age = age; ViewBag.Gender = gender; ViewBag.Caption = caption; } //............................................................. // Emotion Service API var emotionServiceClient = new EmotionServiceClient("1829328c70be4f8aa8cb16da23ba10b2"); // should be in appsettings using (Stream imageFileStream = System.IO.File.OpenRead(path)) { // emotion payload var emotionResult = await emotionServiceClient.RecognizeAsync(imageFileStream); Dictionary <string, double> emoResultDictionary = new Dictionary <string, double>(); if (emotionResult.Length != 0) { foreach (var item in emotionResult) { emoResultDictionary.Add("Fear", item.Scores.Fear); emoResultDictionary.Add("Contempt", item.Scores.Contempt); emoResultDictionary.Add("Disgust", item.Scores.Disgust); emoResultDictionary.Add("Anger", item.Scores.Anger); emoResultDictionary.Add("Happiness", item.Scores.Happiness); emoResultDictionary.Add("Surprise", item.Scores.Surprise); emoResultDictionary.Add("Neutral", item.Scores.Neutral); } } // get key with highest value var confidentEmotion = string.Empty; if (emoResultDictionary.Count != 0) { confidentEmotion = emoResultDictionary.Aggregate((l, r) => l.Value > r.Value ? l : r).Key; ViewBag.Emotion = confidentEmotion; } else { ViewBag.Emotion = "No Emotion dectected"; } //............................................................. // bing image search API // limit results to 5 for similar images based on emotion and caption List <SearchResult> result = BingWebSearcher.Search(confidentEmotion + " " + caption); ViewBag.Images = new String[5]; for (var i = 0; i < 5 && i < result.Count; i++) { ViewBag.Images[i] = result[i].Link; } } } return(View("Index")); }