Ejemplo n.º 1
0
        void bw_StartProxyList(object sender, DoWorkEventArgs e)
        {
            FormControlHelper.ControlInvoke(textBoxProxyList, () => textBoxProxyList.Enabled = false);

            string[] tokens = Regex.Split(textBoxProxyList.Text, @"\r?\n|\r");

            int lines        = tokens.Length;
            int linesCounter = 0;

            threads = 1;

            FormControlHelper.ControlInvoke(progressBar, () => progressBar.Maximum = lines);
            while ((threads > 0) && (linesCounter <= lines))
            {
                if (threads < MaxThreads)
                {
                    BackgroundWorker bw = new BackgroundWorker();
                    bw.WorkerReportsProgress = true;
                    //bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
                    bw.DoWork += new DoWorkEventHandler(bw_DoList);
                    bw.RunWorkerAsync();
                    linesCounter++;
                    threads++;
                }
            }
        }
Ejemplo n.º 2
0
        void bw_DoList(object sender, DoWorkEventArgs e)
        {
            string[] tokens = Regex.Split(textBoxProxyList.Text, @"\r?\n|\r");
            if ((tokens.Length > currentline) && (!string.IsNullOrEmpty(tokens[currentline])))
            {
                string ProxyIP   = Regex.Split(tokens[currentline].Replace("http://", ""), @":|\t")[0];
                string ProxyPort = Regex.Split(tokens[currentline].Replace("http://", ""), @":|\t")[1];
                currentline++;
                FormControlHelper.ControlInvoke(progressBar, () => progressBar.Value = currentline - 1);
                if ((IPAddress.TryParse(ProxyIP, out _)) && (int.TryParse(ProxyPort, out int i)))
                {
                    /*FormControlHelper.ControlInvoke(listViewProxyList, () =>
                     * {
                     *  if (!ProxyMatches(listViewProxyList, ProxyIP, ProxyPort)) CheckProxy(ProxyIP, i);
                     * });*/
                    if (!ProxyMatches(listViewProxyList, ProxyIP, ProxyPort))
                    {
                        CheckProxy(ProxyIP, i);
                    }
                }
            }
            else
            {
                currentline++;
            }
            threads--;

            if (threads <= 1)
            {
                FormControlHelper.ControlInvoke(textBoxProxyList, () => textBoxProxyList.Enabled = true);
                FormControlHelper.ControlInvoke(progressBar, () => progressBar.Value             = 0);
            }
        }
Ejemplo n.º 3
0
 void bw_DoWork(object sender, DoWorkEventArgs e)
 {
     if ((IPAddress.TryParse(textBoxProxyIP.Text, out IPAddress address)) && (int.TryParse(textBoxProxyPort.Text, out int i)))
     {
         FormControlHelper.ControlInvoke(listViewProxyList, () =>
         {
             if (!ProxyMatches(listViewProxyList, textBoxProxyIP.Text, textBoxProxyPort.Text))
             {
                 CheckProxy(textBoxProxyIP.Text, Convert.ToInt32(textBoxProxyPort.Text));
             }
         });
     }
 }
Ejemplo n.º 4
0
        private bool ProxyMatches(ListView Listview, string Proxy, string Port)
        {
            try
            {
                if ((Listview.FindItemWithText(Proxy, false, 0, false).Text == Proxy) && (Listview.FindItemWithText(Proxy, false, 0, false).SubItems[1].Text == Port))
                {
                    FormControlHelper.ControlInvoke(richTextBoxLog, () =>
                    {
                        AppendLogText(Proxy + ":" + Port + " already exist in list", Color.Black, true);
                        //richTextBoxLog.AppendText("\r\n" + Proxy + ":" + Port + " already exist in list");
                    });
                    return(true);
                }
            }
            catch
            {
                return(false);
            }

            return(false);
        }
Ejemplo n.º 5
0
        bool CheckProxy(string IP, int Port)
        {
            System.Diagnostics.Stopwatch timer = new Stopwatch();
            timer.Start();
            try
            {
                IWebProxy      proxy        = new WebProxy(IP, Port);
                HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create("http://ip-api.com/xml/");
                myWebRequest.Timeout = 10000;
                myWebRequest.Proxy   = proxy;
                WebResponse response = myWebRequest.GetResponse();
                using (Stream dataStream = response.GetResponseStream())
                {
                    StreamReader reader             = new StreamReader(dataStream);
                    string       responseFromServer = reader.ReadToEnd();
                    response.Close();
                    timer.Stop();

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(responseFromServer);

                    ListViewItem Item = new ListViewItem();
                    if (((XmlNode)doc.DocumentElement.SelectSingleNode("query")).InnerText == IP)
                    {
                        //Item.SubItems.Add(((XmlNode)doc.DocumentElement.SelectSingleNode("query")).InnerText);
                        Item.Text = ((XmlNode)doc.DocumentElement.SelectSingleNode("query")).InnerText;
                    }
                    else
                    {
                        //Item.SubItems.Add(IP);
                        Item.Text = IP;
                    }
                    Item.SubItems.Add(Port.ToString());
                    Item.SubItems.Add(timer.Elapsed.TotalMilliseconds.ToString());
                    Item.SubItems.Add(Boolean.TrueString);
                    Item.SubItems.Add(((XmlNode)doc.DocumentElement.SelectSingleNode("countryCode")).InnerText);
                    Item.SubItems.Add(((XmlNode)doc.DocumentElement.SelectSingleNode("regionName")).InnerText);
                    Item.SubItems.Add(((XmlNode)doc.DocumentElement.SelectSingleNode("city")).InnerText);
                    //if (!string.IsNullOrWhiteSpace(doc.DocumentElement.SelectSingleNode("zip").InnerText))
                    Item.SubItems.Add(" " + ((XmlNode)doc.DocumentElement.SelectSingleNode("zip")).InnerText);// else Item.SubItems.Add("0");
                    Item.SubItems.Add(((XmlNode)doc.DocumentElement.SelectSingleNode("lat")).InnerText + ", " + ((XmlNode)doc.DocumentElement.SelectSingleNode("lon")).InnerText);
                    Item.SubItems.Add(((XmlNode)doc.DocumentElement.SelectSingleNode("timezone")).InnerText);
                    Item.SubItems.Add(((XmlNode)doc.DocumentElement.SelectSingleNode("isp")).InnerText);
                    Item.SubItems.Add(((XmlNode)doc.DocumentElement.SelectSingleNode("org")).InnerText);

                    FormControlHelper.ControlInvoke(listViewProxyList, () => listViewProxyList.Items.Add(Item));

                    if (String.IsNullOrWhiteSpace(responseFromServer))
                    {
                        Item.BackColor = Color.Red;
                        return(false);
                    }
                    else
                    {
                        if (timer.Elapsed.TotalMilliseconds < 3000)
                        {
                            Item.BackColor = Color.LightGreen;
                        }
                        else if ((timer.Elapsed.TotalMilliseconds > 3000) && (timer.Elapsed.TotalMilliseconds < 6000))
                        {
                            Item.BackColor = Color.Yellow;
                        }
                        else if ((timer.Elapsed.TotalMilliseconds > 6000) && (timer.Elapsed.TotalMilliseconds < 8000))
                        {
                            Item.BackColor = Color.Orange;
                        }
                        else if (timer.Elapsed.TotalMilliseconds > 8000)
                        {
                            Item.BackColor = Color.DarkOrange;
                        }
                        return(true);
                    }
                }
            }
            catch
            {
                timer.Stop();
                ListViewItem Item = new ListViewItem();
                Item.Text = IP.ToString();
                Item.SubItems.Add(Port.ToString());
                //Item.SubItems.Add("Dead or timeout");
                Item.SubItems.Add(timer.Elapsed.TotalMilliseconds.ToString());
                Item.SubItems.Add(Boolean.FalseString);
                Item.SubItems.Add("");
                Item.SubItems.Add("");
                Item.SubItems.Add("");
                Item.SubItems.Add("");
                Item.SubItems.Add("");
                Item.SubItems.Add("");
                Item.SubItems.Add("");
                Item.SubItems.Add("");
                Item.BackColor = Color.Red;
                FormControlHelper.ControlInvoke(listViewProxyList, () => listViewProxyList.Items.Add(Item));
                return(false);
            }
        }