多任务检查代理

时间:2010-09-24 11:33:25

标签: c# .net-3.5 proxies anonymity

我写了那个小程序:

string sciezka = "http://proxyjudge.hell-spy.de/";

        foreach(var ip in listBox1.Items)
        {
            ////////////////// CHANGES IP:PORT TO WEBPROXY HOST,PORT
            string host=null;
            string zmiana=null;
            string sport = null;
            int port=0;
            int pozycja=0;
            zmiana=ip.ToString();
            pozycja=zmiana.IndexOf(":");
            host=zmiana.Remove(pozycja);
            sport = zmiana.Replace(host + ":", "");
            port = int.Parse(sport);
            ////////////////////////////////////////// CONNECTING TO PROXYJUDGE
            string anonymous=null;
            try
            {
                WebRequest request = WebRequest.Create(sciezka);
                WebProxy myprox = new WebProxy(host, port);
                request.Timeout = 5000;
                request.Proxy = myprox;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream strumien = response.GetResponseStream();
                StreamReader sr = new StreamReader(strumien);
                anonymous = sr.ReadToEnd();
                if (anonymous.Contains("HTTP_VIA"))
                {
                    listBox3.Items.Add(zmiana);
                }
                else
                {
                    listBox2.Items.Add(zmiana);
                }
                Update();
                request.Abort();

                sr.Close();
            }
            catch (Exception ex)
            {
                listBox3.Items.Add(zmiana);
                Update();

            }

我希望它同时检查几个代理...不是一个一个:) 有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

好吧,你可以使用.AsParallel extension method

更改

foreach(var ip in listBox1.Items)

foreach(var ip in listBox1.Items.AsParallel())