Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.NetworkInformation;
- using System.Net.Sockets;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace instabot
- {
- class Proxy
- {
- private static bool PingHost(string strIP, int intPort)
- {
- bool blProxy = false;
- try
- {
- TcpClient client = new TcpClient(strIP, intPort);
- blProxy = true;
- }
- catch (Exception ex)
- {
- return false;
- }
- return blProxy;
- }
- public static string GetProxy()
- {
- string proxyip = "";
- var urlAddress = "https://www.us-proxy.org";
- //<td>35.190.133.37</td><td>80</td><td class='hm'>United States</td><td>anonymous</td><td class='hm'>no</td>
- WebRequest reqGET = System.Net.WebRequest.Create(urlAddress);
- WebResponse resp;
- try
- {
- resp = reqGET.GetResponse();
- System.IO.Stream stream = resp.GetResponseStream();
- System.IO.StreamReader sr = new System.IO.StreamReader(stream);
- string s = sr.ReadToEnd();
- 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>)";
- Regex regex = new Regex(pattern);
- Match match = regex.Match(s);
- proxyip = "";
- while (match.Success)
- {
- var ip_port = match.Groups[1].Value.Replace(" class='hm'", "");
- string[] keys = ip_port.Split(new[] { "</td><td>" }, StringSplitOptions.None);
- for (int i = 0; i < keys.Length; i++)
- {
- keys[i] = keys[i].Replace("</td>", "").Replace("<td>", "");
- }
- Console.WriteLine(keys[0]+':'+keys[1]+" "+keys[6]);
- if (keys[6] == "yes")
- {
- if (PingHost(keys[0], int.Parse(keys[1])))
- return proxyip += "https://" + keys[0] + ':' + keys[1];
- }
- else
- {
- if (PingHost(keys[0], int.Parse(keys[1])))
- return proxyip += "http://" + keys[0] + ':' + keys[1];
- }
- match = match.NextMatch();
- }
- }
- catch (WebException)
- {
- }
- return "Error";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement