/* * Check all the proxies */ private static void CheckProxies() { // Load the proxies List <string> proxiesList; try { proxiesList = new List <string>(File.ReadAllLines(_proxyPath)); _totalProxies = proxiesList.Count; } catch (Exception e) { Console.WriteLine($"$ {e.Message}"); return; } // Clear doubles if (_removeDuplicates) { proxiesList = proxiesList.Distinct().ToList(); } Statistics handler = UpdateStatistics; // Start checking Parallel.ForEach(proxiesList, new ParallelOptions { MaxDegreeOfParallelism = _threads }, p => { HttpRequest request = null; try { request = new HttpRequest { Proxy = _proxyType switch { "HTTP" => HttpProxyClient.Parse(p), "HTTPS" => HttpProxyClient.Parse(p), "SOCKS4" => Socks4ProxyClient.Parse(p), "SOCKS4A" => Socks4AProxyClient.Parse(p), "SOCKS5" => Socks5ProxyClient.Parse(p), _ => HttpProxyClient.Parse(p) },
/// <summary> /// Return a parsed and ready-to-use proxy /// </summary> /// <returns>ProxyClient</returns> public ProxyClient GetParsedProxy() { // Switch type switch (Type) { case ProxyType.HTTP: return(HttpProxyClient.Parse(Full)); case ProxyType.Socks4: return(Socks4ProxyClient.Parse(Full)); case ProxyType.Socks4A: return(Socks4AProxyClient.Parse(Full)); case ProxyType.Socks5: return(Socks5ProxyClient.Parse(Full)); default: return(null); } }
public static void Change(HttpRequest req, string proxy, ProxyType proxyType) { if (proxy != null && proxy != "" && req != null) { if (proxyType == ProxyType.HTTPS) { req.Proxy = HttpProxyClient.Parse(proxy); } else if (proxyType == ProxyType.SOCKS4) { req.Proxy = Socks4ProxyClient.Parse(proxy); } else if (proxyType == ProxyType.SOCKS4A) { req.Proxy = Socks4AProxyClient.Parse(proxy); } else { req.Proxy = Socks5ProxyClient.Parse(proxy); } } }
/// <inheritdoc /> public override void Process(BotData data) { base.Process(data); // If the clearance info is already set and we're not getting it fresh each time, skip if (data.UseProxies) { if (data.Proxy.Clearance != "" && data.Proxy.Cfduid != "" && !data.GlobalSettings.Proxies.AlwaysGetClearance) { data.Log(new LogEntry("Skipping CF Bypass because there is already a valid cookie", Colors.White)); return; } } var localUrl = ReplaceValues(url, data); var uri = new Uri(localUrl); var timeout = data.GlobalSettings.General.RequestTimeout * 1000; var request = new HttpRequest(); request.IgnoreProtocolErrors = true; request.ConnectTimeout = timeout; request.ReadWriteTimeout = timeout; request.Cookies = new CookieStorage(); foreach (var cookie in data.Cookies) { request.Cookies.Add(new Cookie(cookie.Key, cookie.Value, "/", uri.Host)); } if (data.UseProxies) { switch (data.Proxy.Type) { case Extreme.Net.ProxyType.Http: request.Proxy = HttpProxyClient.Parse(data.Proxy.Proxy); break; case Extreme.Net.ProxyType.Socks4: request.Proxy = Socks4ProxyClient.Parse(data.Proxy.Proxy); break; case Extreme.Net.ProxyType.Socks4a: request.Proxy = Socks4AProxyClient.Parse(data.Proxy.Proxy); break; case Extreme.Net.ProxyType.Socks5: request.Proxy = Socks5ProxyClient.Parse(data.Proxy.Proxy); break; case Extreme.Net.ProxyType.Chain: throw new Exception("The Chain Proxy Type is not supported in Leaf.xNet (used for CF Bypass)."); } request.Proxy.ReadWriteTimeout = timeout; request.Proxy.ConnectTimeout = timeout; request.Proxy.Username = data.Proxy.Username; request.Proxy.Password = data.Proxy.Password; } request.UserAgent = ReplaceValues(userAgent, data); var twoCapToken = data.GlobalSettings.Captchas.TwoCapToken; if (twoCapToken != "") { request.CaptchaSolver = new TwoCaptchaSolver() { ApiKey = data.GlobalSettings.Captchas.TwoCapToken } } ; var response = request.GetThroughCloudflare(new Uri(localUrl)); var responseString = response.ToString(); // Save the cookies var ck = response.Cookies.GetCookies(localUrl); var clearance = ""; var cfduid = ""; try { clearance = ck["cf_clearance"].Value; cfduid = ck["__cfduid"].Value; } catch { } if (data.UseProxies) { data.Proxy.Clearance = clearance; data.Proxy.Cfduid = cfduid; } if (clearance != "") { data.Log(new LogEntry("Got Cloudflare clearance!", Colors.GreenYellow)); data.Log(new LogEntry(clearance + Environment.NewLine + cfduid + Environment.NewLine, Colors.White)); } // Get code data.ResponseCode = ((int)response.StatusCode).ToString(); if (PrintResponseInfo) { data.Log(new LogEntry($"Response code: {data.ResponseCode}", Colors.Cyan)); } // Get headers if (PrintResponseInfo) { data.Log(new LogEntry("Received headers:", Colors.DeepPink)); } var receivedHeaders = response.EnumerateHeaders(); data.ResponseHeaders.Clear(); while (receivedHeaders.MoveNext()) { var header = receivedHeaders.Current; data.ResponseHeaders.Add(header.Key, header.Value); if (PrintResponseInfo) { data.Log(new LogEntry($"{header.Key}: {header.Value}", Colors.LightPink)); } } if (!response.ContainsHeader(HttpHeader.ContentLength)) { if (data.ResponseHeaders.ContainsKey("Content-Encoding") && data.ResponseHeaders["Content-Encoding"].Contains("gzip")) { data.ResponseHeaders["Content-Length"] = GZip.Zip(responseString).Length.ToString(); } else { data.ResponseHeaders["Content-Length"] = responseString.Length.ToString(); } if (PrintResponseInfo) { data.Log(new LogEntry($"Content-Length: {data.ResponseHeaders["Content-Length"]}", Colors.LightPink)); } } // Get cookies if (PrintResponseInfo) { data.Log(new LogEntry("Received cookies:", Colors.Goldenrod)); } foreach (Cookie cookie in response.Cookies.GetCookies(localUrl)) { if (data.Cookies.ContainsKey(cookie.Name)) { data.Cookies[cookie.Name] = cookie.Value; } else { data.Cookies.Add(cookie.Name, cookie.Value); } if (PrintResponseInfo) { data.Log(new LogEntry($"{cookie.Name}: {cookie.Value}", Colors.LightGoldenrodYellow)); } } data.ResponseSource = responseString; if (PrintResponseInfo) { data.Log(new LogEntry("Response Source:", Colors.Green)); data.Log(new LogEntry(data.ResponseSource, Colors.GreenYellow)); } } }