How to connect webclient with proxies

  • Thread starter Thread starter BataBo Jokviu
  • Start date Start date
B

BataBo Jokviu

Guest
So in the past I've made 2 web scapers and they both have an issue I dont want to discuss about here.But I foundd out from competitors that I need to use proxies.So here is what I would like to do:User puts proxie list in special Proxies.txt file and for every interation it connects to mojang api with different proxy.

Here is my code:

class Program
{
static Regex idcheck = new Regex(@"id"":""(.+?)"",");
static Regex Migrationcheck = new Regex(@"legacy"":(.+?)}");

private static String _outputFileUnmigrated = "Unmigrated.txt";
private static String _outputFileMigrated = "Migrated.txt";

static void Main(string[] args)
{
var lines = File.ReadLines("List.txt");
var UnmigratedNumber = 0;
var MigratedNumber = 0;
Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + (UnmigratedNumber + MigratedNumber) + " | Good:" + UnmigratedNumber;

using (StreamWriter UnmigratedWriter = File.AppendText(_outputFileUnmigrated))
{
using (StreamWriter MigratedWriter = File.AppendText(_outputFileMigrated))
{
foreach (var line in lines)
{
args = new[]
{
"https://api.mojang.com/users/profiles/minecraft/" + line
};

using (var client1 = new WebClient())
{
var content = ScrubContent(client1.DownloadString(args[0]));
var idchecked = idcheck.Matches(content).Cast<Match>().Single().Groups[1];

args = new[]
{
"https://sessionserver.mojang.com/session/minecraft/profile/" + idchecked

};
using (var client2 = new WebClient())
{
var content1 = ScrubContent(client2.DownloadString(args[0]));
try {
var migrationchecked = Migrationcheck.Matches(content1).Cast<Match>().Single().Groups[1];
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("UNMIGRATED " + line);
UnmigratedWriter.WriteLine(line);
UnmigratedNumber++;
Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + (UnmigratedNumber + MigratedNumber) + " | Good:" + UnmigratedNumber;
}
catch(InvalidOperationException ex)
{

Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("MIGRATED " + line);
MigratedWriter.WriteLine(line);
MigratedNumber++;
Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + (UnmigratedNumber + MigratedNumber) + " | Good:" + UnmigratedNumber;
}




}
}



}
}
}
Console.WriteLine("");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("====================Results====================");
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Checked: {0} names", UnmigratedNumber + MigratedNumber);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Unmigrated: {0} accounts", UnmigratedNumber);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Migrated: {0} accounts", MigratedNumber);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("====================Results====================");
Console.ReadLine();
}

static string ScrubContent(string content)
{
return new string(content.Where(c => c != '\n').ToArray());
}
}


Sorry for asking so many qeustions I'm just not good at c#

Continue reading...
 
Back
Top