|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Net; |
| 5 | + |
| 6 | +namespace RandomProxy |
| 7 | +{ |
| 8 | + class GetProxy |
| 9 | + { |
| 10 | + |
| 11 | + public enum proxyType |
| 12 | + { |
| 13 | + http, |
| 14 | + https, |
| 15 | + socks5, |
| 16 | + all, |
| 17 | + } |
| 18 | + |
| 19 | + public class getFullProxy |
| 20 | + { |
| 21 | + public getFullProxy(proxyType type = GetProxy.proxyType.all) |
| 22 | + { |
| 23 | + string Proxytype = "all"; |
| 24 | + switch (type) |
| 25 | + { |
| 26 | + case proxyType.all: |
| 27 | + Proxytype = "all"; |
| 28 | + break; |
| 29 | + case proxyType.http: |
| 30 | + Proxytype = "http"; |
| 31 | + break; |
| 32 | + case proxyType.https: |
| 33 | + Proxytype = "https"; |
| 34 | + break; |
| 35 | + case proxyType.socks5: |
| 36 | + Proxytype = "socks5"; |
| 37 | + break; |
| 38 | + } |
| 39 | + string link = "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=" + Proxytype + "&timeout=10000&country=all&ssl=all&anonymity=all"; |
| 40 | + |
| 41 | + WebClient client = new WebClient(); |
| 42 | + |
| 43 | + string data = client.DownloadString(link); |
| 44 | + List<string> proxyList = new List<string>(); |
| 45 | + proxyList.AddRange(data.Split("\n")); |
| 46 | + Random rdm = new Random(); |
| 47 | + |
| 48 | + ProxyType = Proxytype; |
| 49 | + ProxyList = proxyList.ToArray(); |
| 50 | + ProxyCount = ProxyList.Count(); |
| 51 | + Proxy = ProxyList[rdm.Next(ProxyList.Count())]; |
| 52 | + |
| 53 | + } |
| 54 | + public string? ProxyType { get; set; } |
| 55 | + public string[]? ProxyList { get; set; } |
| 56 | + public int? ProxyCount { get; set; } |
| 57 | + public string? Proxy { get; set; } |
| 58 | + } |
| 59 | + |
| 60 | + public static string getRandomProxy(proxyType type = proxyType.all) |
| 61 | + { |
| 62 | + string Proxytype = "all"; |
| 63 | + switch (type) |
| 64 | + { |
| 65 | + case proxyType.all: |
| 66 | + Proxytype = "all"; |
| 67 | + break; |
| 68 | + case proxyType.http: |
| 69 | + Proxytype = "http"; |
| 70 | + break; |
| 71 | + case proxyType.https: |
| 72 | + Proxytype = "https"; |
| 73 | + break; |
| 74 | + case proxyType.socks5: |
| 75 | + Proxytype = "socks5"; |
| 76 | + break; |
| 77 | + } |
| 78 | + string link = "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=" + Proxytype + "&timeout=10000&country=all&ssl=all&anonymity=all"; |
| 79 | + |
| 80 | + WebClient client = new WebClient(); |
| 81 | + |
| 82 | + string data = client.DownloadString(link); |
| 83 | + List<string> proxyList = new List<string>(); |
| 84 | + proxyList.AddRange(data.Split("\n")); |
| 85 | + Random rdm = new Random(); |
| 86 | + return proxyList[rdm.Next(proxyList.Count)]; |
| 87 | + } |
| 88 | + |
| 89 | + public static string[] getProxyList(proxyType type = proxyType.all) |
| 90 | + { |
| 91 | + string Proxytype = "all"; |
| 92 | + switch (type) |
| 93 | + { |
| 94 | + case proxyType.all: |
| 95 | + Proxytype = "all"; |
| 96 | + break; |
| 97 | + case proxyType.http: |
| 98 | + Proxytype = "http"; |
| 99 | + break; |
| 100 | + case proxyType.https: |
| 101 | + Proxytype = "https"; |
| 102 | + break; |
| 103 | + case proxyType.socks5: |
| 104 | + Proxytype = "socks5"; |
| 105 | + break; |
| 106 | + } |
| 107 | + string link = "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=" + Proxytype + "&timeout=10000&country=all&ssl=all&anonymity=all"; |
| 108 | + |
| 109 | + WebClient client = new WebClient(); |
| 110 | + |
| 111 | + string data = client.DownloadString(link); |
| 112 | + List<string> proxyList = new List<string>(); |
| 113 | + proxyList.AddRange(data.Split("\n")); |
| 114 | + Random rdm = new Random(); |
| 115 | + return proxyList.ToArray(); |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + } |
| 120 | +} |
0 commit comments