Instantly share code, notes, and snippets.

Embed
What would you like to do?
namespace ConsoleApplication
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using RestSharp;
public class Program
{
private const int RequestTimeout = 10000;
private const int SleepMin = 2;
private const int SleepMax = 15;
public static void Main(string[] args)
{
var sleepMin = SleepMin;
var sleepMax = SleepMax;
if (args != null && args.Length == 2)
{
int.TryParse(args[0], out sleepMin);
int.TryParse(args[1], out sleepMax);
}
bool isRunning = true;
var task = Task.Factory.StartNew(() =>
{
var random = new Random();
var nextRun = DateTime.Now;
do
{
if (nextRun <= DateTime.Now)
{
Console.WriteLine("Current IP: {0}", GetIp());
try
{
NewVote();
}
catch (Exception e)
{
Console.WriteLine("Voting failed: {0}", e.Message);
}
var sleepTime = random.Next(sleepMin, sleepMax);
Console.WriteLine("Sleeping {0} secs.", sleepTime);
nextRun = DateTime.Now.Add(TimeSpan.FromSeconds(sleepTime));
}
Thread.Sleep(200);
}
while (isRunning);
}, TaskCreationOptions.LongRunning);
Console.WriteLine("Press any key to stop...");
Console.ReadKey();
Console.WriteLine("Stopping...");
isRunning = false;
// Wait for task to finish
task.Wait();
}
private static void NewVote()
{
var rand = new Random();
var jqueryRandom = new[] { rand.Next(1000, 9000), rand.Next(1000, 9000), rand.Next(1000, 9000), rand.Next(1000, 9000), rand.Next(1000, 9000) };
var jqueryTimestamp = GetCurrentUnixTimestampMillis() - rand.Next(1000, 9000);
var jqueryCallback = string.Format("jQuery{0}_{1}", string.Join(string.Empty, jqueryRandom), jqueryTimestamp);
var timestamp = GetCurrentUnixTimestampMillis();
var voteUrl = string.Format("http://vote.musiqueplus.com/vote.php?callback={0}&barid=geekOct17&buttonid=Simon&action=click&_={1}", jqueryCallback, timestamp);
Console.WriteLine("GET {0}", voteUrl);
var c = new RestClient { Proxy = WebRequest.DefaultWebProxy };
c.AddDefaultHeader("Referer", "http://www.musiqueplus.com/videos/geek-recherche-simon-carpentier-1.1245456");
var result = c.Get(new RestRequest(voteUrl) { Timeout = RequestTimeout });
Console.WriteLine("Result:");
Console.WriteLine(result.Content);
}
private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static long GetCurrentUnixTimestampMillis()
{
return (long)(DateTime.UtcNow - UnixEpoch).TotalMilliseconds;
}
private static string GetIp()
{
////<strong>IP Address = </strong>96.47.226.21<br><br>
var client = new RestClient("http://www.ventrilo.com/myip.php");
var result = client.Get(new RestRequest());
var match = Regex.Match(result.Content, "IP Address = </strong>(.*)<br><br>");
return match.Success ? match.Groups[1].Value : string.Empty;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment