internal static void WriteTempContent(SpinProxiesRootResponse data, SpinProxiesProxyClass proxyClass) { // For viewing live data try { string content = data.ToJson(); var normalizedProxyClass = proxyClass.ToString().ToLower(); var tempProxyListFilePath = String.Format(tempProxyListFilePathFormat, normalizedProxyClass); lock (locker) { File.WriteAllText(tempProxyListFilePath, content); } } catch { } }
private ProxyTester() { spinProxiesApiWrapper = new SpinProxiesApiWrapper(); spinProxiesData = spinProxiesApiWrapper.FetchProxyList(SpinProxiesProxyClass.Socks5); probeProxyHeaderBuffer = new FluentHeaderBuilder() .AddMethod("http://c.statcounter.com/11592521/0/dc42a2e3/0/", HttpMethod.Get) .Add(HttpRequestHeader.Host, "c.statcounter.com") .Add(HttpRequestHeader.Connection, "keep-alive") .Add(HttpRequestHeader.CacheControl, "max-age=0") .AddCustom("Upgrade-Insecure-Requests", "1") .Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36") .Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") .Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate") .Add(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.9,ro;q=0.8") .Add(HttpRequestHeader.Pragma, "no-cache") .BuildAsByteArray(); }
private static void WriteMasterContent(SpinProxiesRootResponse data, SpinProxiesProxyClass proxyClass, bool writeOriginalFile = true) { string content = data.ToJson(); var normalizedProxyClass = proxyClass.ToString().ToLower(); var masterProxyListFilePath = String.Format(masterProxyListFilePathFormat, normalizedProxyClass); lock (locker) { File.WriteAllText(masterProxyListFilePath, content); if (writeOriginalFile) { var projectMasterProxyListFilePath = $"../../../{masterProxyListFilePath}"; if (File.Exists(projectMasterProxyListFilePath)) { File.WriteAllText(projectMasterProxyListFilePath, content); } } } }
public SpinProxiesRootResponse FetchProxyList(SpinProxiesProxyClass proxyClass) { const string apiKey = "qmml9lwkny4j3x9yyt4ed2oscp20lu"; var normalizedProxyClass = proxyClass.ToString().ToLower(); using (var client = new WebClient()) { client.Headers[HttpRequestHeader.Accept] = "application/json"; string result = null; try { result = client.DownloadString( $"https://spinproxies.com/api/v1/proxylist?key={apiKey}&type=anonymous&protocols={normalizedProxyClass}&format=json" ); } catch { } SpinProxiesRootResponse data = null; if (!String.IsNullOrEmpty(result)) { try { data = SpinProxiesRootResponse.FromJson(result); } catch { } } var masterProxyListFilePath = String.Format(masterProxyListFilePathFormat, normalizedProxyClass); if (null != data) { if (File.Exists(masterProxyListFilePath)) { var temp = File.ReadAllText(masterProxyListFilePath); var storedData = SpinProxiesRootResponse.FromJson(temp); storedData.Data.Proxies.AddRange(data.Data.Proxies); var uniqueProxies = storedData.Data.Proxies.GroupBy(w => new { w.Ip, w.Port }).Select(w => w.FirstOrDefault()); storedData.Data.Proxies = uniqueProxies.ToList(); WriteMasterContent(storedData, proxyClass); return(storedData); } else { WriteMasterContent(data, proxyClass); } } else { if (File.Exists(masterProxyListFilePath)) { var temp = File.ReadAllText(masterProxyListFilePath); var storedData = SpinProxiesRootResponse.FromJson(temp); return(storedData); } } return(data); } }