Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using xNet;
- namespace GitChecker
- {
- class Site
- {
- public string Url = null; //URL сайта
- public bool GitExist = false; //существует ли .git
- public bool Git403 = false; //существует, но 403
- public Site(string _Url)
- {
- //инициализатор класса
- Url = _Url;
- }
- public void GitCheck()
- {
- //проверка на сущетвование .git дериктории
- HttpRequest Request = new HttpRequest();
- Request.IgnoreProtocolErrors = true;
- Request.UserAgent = Http.ChromeUserAgent();
- Request.ConnectTimeout = 10000;
- try
- {
- HttpResponse Responce = Request.Get(Url + "/.git/config");
- string Result = Responce.ToString();
- GitExist = Result.Contains("[core]");
- Git403 = (Responce.StatusCode == HttpStatusCode.Forbidden);
- Request.Close();
- Request.Dispose();
- }
- catch
- {
- GitExist = false;
- }
- }
- }
- class Checker
- {
- public List<Site> Sites = new List<Site>(); //Сайты
- int CheckCount = 0;
- int CheckGood = 0;
- private object Locker = new object();
- public void CheckStart()
- {
- //Проверка сайтов из списка
- CheckCount = 0;
- CheckGood = 0;
- Parallel.For(0, Sites.Count, new ParallelOptions { MaxDegreeOfParallelism = 500 },
- i =>
- {
- int x = i;
- Sites[i].GitCheck();
- if (Sites[i].Git403)
- {
- lock (Locker)
- {
- ++CheckCount;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine(Sites[i].Url + " -> Git Forbidden. [{0}/{1}/{2}]",CheckGood,CheckCount,Sites.Count);
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- }
- else
- {
- if (Sites[i].GitExist)
- {
- lock (Locker)
- {
- ++CheckCount;
- ++CheckGood;
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(Sites[i].Url + " -> Git exist! [{0}/{1}/{2}]",CheckGood,CheckCount,Sites.Count);
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- }
- else
- {
- lock (Locker)
- {
- ++CheckCount;
- Console.WriteLine(Sites[i].Url + " -> Git don't exist :( [{0}/{1}/{2}]",CheckGood,CheckCount,Sites.Count);
- }
- }
- }
- });
- }
- public void SiteAdd(string Url)
- {
- //Добавление сайта в список
- Site N = new Site(Url);
- //N.GitExist = true;
- Sites.Add(N);
- }
- public void AddFromRambler()
- {
- HttpRequest Request = new HttpRequest();
- Request.IgnoreProtocolErrors = true;
- Request.UserAgent = Http.ChromeUserAgent();
- Request.ConnectTimeout = 10000;
- Regex regex = new Regex("\"([^\"]{1,})\"[ \r\n]{1,}class=\"link link_catalogue-site-link\"");
- for (int i = 1; i <= 27; ++i) //to 40
- {
- HttpResponse Responce = Request.Get("http://top100.rambler.ru/navi/?theme=1166%2F1167&statord=1&page="+i);
- string Result = Responce.ToString();
- Match match = regex.Match(Result);
- while (match.Success)
- {
- SiteAdd(match.Groups[1].Value);
- match = match.NextMatch();
- }
- Console.WriteLine("Page #{0} is downloaded...",i);
- }
- Request.Close();
- Request.Dispose();
- }
- public void AddFromDump()
- {
- //Добавление сайтов из сырого дампа
- string Dump = File.ReadAllText("in.txt");
- string[] DumpArray = Dump.Split(new string[] {"\r\n"},StringSplitOptions.RemoveEmptyEntries);
- for(int i=0; i<DumpArray.Length;++i)
- SiteAdd(DumpArray[i]);
- }
- public void SaveResult()
- {
- //Сохранение результата
- string _Out = "";
- for (int i = 0; i < Sites.Count;++i )
- if (Sites[i].GitExist)
- _Out += Sites[i].Url+"\r\n";
- File.WriteAllText("Result.txt", _Out);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Нажмите Enter, чтобы начать...");
- Console.ReadKey();
- Checker Now = new Checker();
- Now.AddFromDump();
- //Now.AddFromRambler();
- Console.WriteLine("Sites count: "+Now.Sites.Count);
- Now.CheckStart();
- Now.SaveResult();
- Console.WriteLine("Done.");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement