• R/O
  • SSH
  • HTTPS

openpishcrawler: Commit


Commit MetaInfo

Revision5 (tree)
Time2019-10-10 12:47:16
Authorsebastiandotnet

Log Message

- add missing source file

Change Summary

Incremental Difference

--- OpenPishCrawler/Service/OpenPishSleep.cs (nonexistent)
+++ OpenPishCrawler/Service/OpenPishSleep.cs (revision 5)
@@ -0,0 +1,74 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using System.Threading.Tasks;
6+using System.IO;
7+using System.Net;
8+using HtmlAgilityPack;
9+using OpenPishCrawler.Data;
10+
11+namespace OpenPishCrawler.Service
12+{
13+ public class OpenPishSleep
14+ {
15+ // Scamers may fake sleeping depending on http header/user agent/ip/etc.
16+ // or wake up the site later.
17+ public bool WebHostAppPageSeemsToBeSleeping(PishingPage page)
18+ {
19+ var result = default(bool);
20+
21+ try
22+ {
23+ if (null == page)
24+ throw new ArgumentNullException(nameof(page));
25+
26+ var document = ReadPageDocument(page.Url);
27+ var sleepy = document.DocumentNode.FirstChild.ChildNodes.FirstOrDefault(e => e.Name == "body")?
28+ .ChildNodes.FirstOrDefault(e => e.Name == "div")?
29+ .ChildNodes.FirstOrDefault(e => e.Name == "div");
30+ result = sleepy?.InnerText == "Website is sleeping.";
31+ }
32+ catch (WebException exception)
33+ {
34+ result = true == exception.Message?.Contains("403");
35+ }
36+ catch
37+ {
38+ ;
39+ }
40+
41+ return result;
42+ }
43+
44+ private HtmlDocument ReadPageDocument(string url)
45+ {
46+ var result = new HtmlDocument();
47+ var page = ReadPage(url);
48+ result.LoadHtml(page);
49+ return result;
50+ }
51+
52+ private string ReadPage(string url)
53+ {
54+ if (!(url.StartsWith("http://") || url.StartsWith("https://")))
55+ url = String.Format("https://{0}", url);
56+
57+ var result = default(string);
58+ using (var webClient = new WebClient())
59+ {
60+ webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
61+ using (var response = webClient.OpenRead(url))
62+ {
63+ using (var reader = new StreamReader(response))
64+ {
65+ result = reader.ReadToEnd();
66+ response.Close();
67+ reader.Close();
68+ }
69+ }
70+ }
71+ return result;
72+ }
73+ }
74+}
Show on old repository browser