Advertisement
KeinMitleid

FP Subforums

Nov 1st, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Net;
  5. using System.Threading.Tasks;
  6.  
  7. class Program
  8. {
  9.     static void Main()
  10.     {
  11.         ServicePointManager.DefaultConnectionLimit = 100;
  12.  
  13.         var stopwatch = new Stopwatch();
  14.         stopwatch.Start();
  15.  
  16.         Console.Write("Username: ");
  17.         string username = Console.ReadLine();
  18.         Console.Write("Password: ");
  19.         string password = Console.ReadLine();
  20.  
  21.         var client = new Client();
  22.         client.Post("login.php?do=login",
  23.     (
  24.         "vb_login_username=" + username +
  25.             "&vb_login_password_hint=Password" +
  26.             "&vb_login_password=" + password +
  27.             "&s=" +
  28.             "&cookieuser=1" +
  29.             "&securitytoken=guest" +
  30.             "&do=login" +
  31.             "&vb_login_md5password=" +
  32.             "&vb_login_md5password_utf="
  33.     ));
  34.  
  35.         string folder = Environment.GetFolderPath(
  36.             Environment.SpecialFolder.Desktop) + @"\Session\";
  37.         if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
  38.  
  39.         int[] subforums =
  40.         {
  41.             6, 15, 16, 36, 38, /*40,*/ 46, 51, 56, 60, 62, 64, 65, 66, 75, 76,
  42.             107, 110, 189, 198, 240, 243, 262, 277, 315, 316, 339, 353, 361,
  43.             383, 384, 385, 389, 391, 393, 394, 396, 397, 401, 403, 408, 409,
  44.             411, 412, 414, 415
  45.         };
  46.  
  47.         Parallel.ForEach(subforums, subforum =>
  48.         {
  49.             client.Get("forumdisplay.php?f=" + subforum);
  50.             File.WriteAllText(folder + subforum + ".htm", client.Page);
  51.         });
  52.  
  53.         stopwatch.Stop();
  54.  
  55.         Console.WriteLine("\nSubforums fetched in {0} seconds",
  56.             (float)stopwatch.ElapsedMilliseconds / 1000);
  57.         Console.Write("Press any key to continue . . . ");
  58.         Console.ReadKey();
  59.     }
  60. }
  61.  
  62. class Client
  63. {
  64.     public HttpStatusCode Code { get; private set; }
  65.     public string Page { get; private set; }
  66.     private CookieContainer _Cookies = new CookieContainer();
  67.  
  68.     public void Get(string path = null)
  69.         { Update(false, path, null); }
  70.  
  71.     public void Post(string path = null, string param = null)
  72.         { Update(true, path, param); }
  73.  
  74.     private void Update(bool post, string path, string param)
  75.     {
  76.         var request = (HttpWebRequest)WebRequest.
  77.             Create("http://www.facepunch.com/" + path);
  78.         request.CookieContainer = _Cookies;
  79.         request.Proxy = null;
  80.  
  81.         if (post)
  82.         {
  83.             request.ContentLength = param.Length;
  84.             request.ContentType = "application/x-www-form-urlencoded";
  85.             request.Method = "POST";
  86.  
  87.             using (var writer = new StreamWriter(request.GetRequestStream()))
  88.                 writer.Write(param);
  89.         }
  90.  
  91.         using (var response = (HttpWebResponse)request.GetResponse())
  92.         using (var reader = new StreamReader(response.GetResponseStream()))
  93.         {
  94.             Page = reader.ReadToEnd();
  95.             Code = response.StatusCode;
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement