Advertisement
KeinMitleid

FP Subforums v2

Nov 2nd, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Net;
  4. using System.Threading.Tasks;
  5.  
  6. class Program
  7. {
  8.     static void Main()
  9.     {
  10.         Console.Write("Username: ");
  11.         string username = Console.ReadLine();
  12.         Console.Write("Password: ");
  13.         string password = Console.ReadLine();
  14.  
  15.         int[] subforums = {
  16.             6, 15, 16, 36, 38, 40, 46, 51, 56, 60, 62, 64, 65, 66, 75, 76, 107,
  17.             110, 189, 198, 240, 243, 262, 277, 315, 316, 339, 353, 361, 383,
  18.             384, 385, 389, 391, 393, 394, 396, 397, 401, 403, 408, 409, 411,
  19.             412, 414, 415 };
  20.  
  21.         ServicePointManager.DefaultConnectionLimit = 10;
  22.         var client = new Client();
  23.         var time = new Stopwatch();
  24.         time.Start();
  25.  
  26.         client.UploadString(
  27.             "http://www.facepunch.com/login.php?do=login",
  28.                 "vb_login_username=" + username +
  29.                 "&vb_login_password_hint=Password" +
  30.                 "&vb_login_password=" + password +
  31.                 "&s=" +
  32.                 "&cookieuser=1" +
  33.                 "&securitytoken=guest" +
  34.                 "&do=login" +
  35.                 "&vb_login_md5password=" +
  36.                 "&vb_login_md5password_utf=");
  37.  
  38.         Parallel.ForEach(subforums, subforum =>
  39.             new Client(client.Cookies).DownloadString(new Uri(
  40.                 "http://www.facepunch.com/forumdisplay.php?f=" + subforum)));
  41.  
  42.         time.Stop();
  43.         Console.WriteLine("\nRequest completed in {0} seconds.",
  44.             ((float)time.ElapsedMilliseconds / 1000).ToString("F3"));
  45.         Console.Write("Press any key to continue . . . ");
  46.         Console.ReadKey();
  47.     }
  48. }
  49.  
  50. public class Client : WebClient
  51. {
  52.     public CookieContainer Cookies { get; private set; }
  53.     public Client(CookieContainer cookies = null)
  54.     {
  55.         Cookies = (cookies != null) ? cookies : new CookieContainer();
  56.         Headers.Add("Content-Type", "application/x-www-form-urlencoded");
  57.     }
  58.  
  59.     protected override WebRequest GetWebRequest(Uri address)
  60.     {
  61.         WebRequest request = base.GetWebRequest(address);
  62.         HttpWebRequest webRequest = request as HttpWebRequest;
  63.         if (webRequest != null) webRequest.CookieContainer = Cookies;
  64.         return request;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement