Advertisement
Guest User

Untitled

a guest
May 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.NetworkInformation;
  6. using System.Net.Sockets;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10.  
  11. namespace instabot
  12. {
  13. class Proxy
  14. {
  15.  
  16. private static bool PingHost(string strIP, int intPort)
  17. {
  18. bool blProxy = false;
  19. try
  20. {
  21. TcpClient client = new TcpClient(strIP, intPort);
  22.  
  23. blProxy = true;
  24. }
  25. catch (Exception ex)
  26. {
  27.  
  28. return false;
  29. }
  30. return blProxy;
  31. }
  32.  
  33. public static string GetProxy()
  34. {
  35. string proxyip = "";
  36. var urlAddress = "https://www.us-proxy.org";
  37. //<td>35.190.133.37</td><td>80</td><td class='hm'>United States</td><td>anonymous</td><td class='hm'>no</td>
  38.  
  39. WebRequest reqGET = System.Net.WebRequest.Create(urlAddress);
  40. WebResponse resp;
  41.  
  42. try
  43. {
  44. resp = reqGET.GetResponse();
  45. System.IO.Stream stream = resp.GetResponseStream();
  46. System.IO.StreamReader sr = new System.IO.StreamReader(stream);
  47. string s = sr.ReadToEnd();
  48.  
  49. string pattern = @"(<td>\d+.\d+.\d+.\d+</td><td>\d+</td><td>\w+</td><td class='hm'>\w+ \w+</td><td>\w+</td><td class='hm'>\w+</td><td>\w+</td>)";
  50. Regex regex = new Regex(pattern);
  51.  
  52. Match match = regex.Match(s);
  53. proxyip = "";
  54. while (match.Success)
  55. {
  56. var ip_port = match.Groups[1].Value.Replace(" class='hm'", "");
  57. string[] keys = ip_port.Split(new[] { "</td><td>" }, StringSplitOptions.None);
  58. for (int i = 0; i < keys.Length; i++)
  59. {
  60. keys[i] = keys[i].Replace("</td>", "").Replace("<td>", "");
  61. }
  62. Console.WriteLine(keys[0]+':'+keys[1]+" "+keys[6]);
  63. if (keys[6] == "yes")
  64. {
  65. if (PingHost(keys[0], int.Parse(keys[1])))
  66. return proxyip += "https://" + keys[0] + ':' + keys[1];
  67. }
  68. else
  69. {
  70. if (PingHost(keys[0], int.Parse(keys[1])))
  71. return proxyip += "http://" + keys[0] + ':' + keys[1];
  72. }
  73. match = match.NextMatch();
  74. }
  75. }
  76. catch (WebException)
  77. {
  78.  
  79. }
  80. return "Error";
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement