Пример #1
0
 public void AddProxyIP(ProxyIP p)
 {
     lock ("add")
     {
         tempProxyList.Add(p);
     }
 }
Пример #2
0
 /// <summary>
 /// 设置IP代理
 /// </summary>
 private void SetProxyIP()
 {
     if (myListView.SelectedIndex == -1)
     {
         MessageBox.Show("没有选中列表项!");
     }
     else
     {
         ProxyIP pp = myListView.SelectedItem as ProxyIP;
         if (string.IsNullOrEmpty(pp.IP) || string.IsNullOrEmpty(pp.Port))
         {
             MessageBox.Show("设置代理失败!");
         }
         else
         {
             try
             {
                 ProxyHelper proxy = new ProxyHelper();
                 proxy.SetProxy(pp.IP, pp.Port);
                 MessageBox.Show("设置代理成功!");
                 msgLabel.Content = "设置代理成功,请重启浏览器!";
             }
             catch
             {
                 MessageBox.Show("设置代理失败!");
             }
         }
     }
 }
Пример #3
0
        public string GetLocalIP(List <ProxyIP> myproxylist, string strLocal)//获取本地IP地址
        {
            string pattern = "\\d+\\.\\d+\\.\\d+\\.\\d+:\\d{2,4}";

            if (Regex.IsMatch(strLocal, pattern))
            {
                int i = 0;
                foreach (Match m in Regex.Matches(strLocal, pattern))
                {
                    ProxyIP myproxy    = new ProxyIP();
                    string  strContent = m.ToString();
                    pattern = "\\d+\\.\\d+\\.\\d+\\.\\d+";
                    if (Regex.IsMatch(strContent, pattern))
                    {
                        myproxy.IP    = Regex.Match(strContent, pattern).ToString();
                        strContent    = Regex.Replace(strContent, pattern, "");
                        strContent    = strContent.Replace(":", "");
                        myproxy.Port  = strContent.Trim();
                        myproxy.Index = i.ToString();
                        myproxylist.Add(myproxy);
                        i++;
                    }
                }
                i--;
                string strBack = string.Format("共为您找到{0}个匹配项", i.ToString());
                return(strBack);
            }
            else
            {
                return("未能找到匹配项!");
            }
        }
Пример #4
0
        public void checkproxy()
        {
            ProxyIP pp = new ProxyIP();

            pp.IP    = "101.71.27.120";
            pp.Port  = "80";
            pp.Place = "未知";
            if (pp != null)
            {
                HttpWebRequest Req;
                WebProxy       proxyObject = new WebProxy(pp.IP, Convert.ToInt32(pp.Port)); // port为端口号 整数型
                Req         = WebRequest.Create("http://www.google.com/") as HttpWebRequest;
                Req.Proxy   = proxyObject;                                                  //设置代理
                Req.Timeout = mySetting.timeout;                                            //超时
                DateTime dt1 = DateTime.Now;
                try
                {
                    if (pp.Place == "未知")
                    {
                        HttpHelper http = new HttpHelper();
                        HttpItem   item = new HttpItem();
                        item.URL = "http://www.ip.cn/index.php?ip=" + pp.IP;
                        HttpResult result   = http.GetHtml(item);
                        string     strPlace = result.Html;
                        if (!string.IsNullOrEmpty(strPlace))
                        {
                            strPlace = Search_string(strPlace, "来自:", "</p><p>");
                            pp.Place = strPlace;
                            //AddProxyIP(pp);
                        }
                    }
                }
                catch { }//忽略错误
                try
                {
                    HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();
                    DateTime        dt2  = DateTime.Now;
                    Encoding        bin  = Encoding.GetEncoding("utf-8");
                    StreamReader    sr   = new StreamReader(Resp.GetResponseStream(), bin);
                    string          str  = sr.ReadToEnd();
                    sr.Close();
                    sr.Dispose();
                    if (str.Contains("百度"))
                    {
                        //result = true;
                        TimeSpan ts = dt2 - dt1;
                        pp.Speed = ((long)ts.TotalMilliseconds).ToString();
                        //AddProxyIP(pp);
                    }
                }
                catch (Exception ex)
                {
                    pp.Speed = "超时";
                    AddProxyIP(pp);
                    Trace.WriteLine(ex.Message);
                }
            }
        }
Пример #5
0
        public string GetCnproxyFreeIP(List <ProxyIP> myproxylist) //正则匹配cn-proxy的ip地址
        {
            string strHtml = GetWebHtml("http://cn-proxy.com/");   //国内代理

            if (!string.IsNullOrEmpty(strHtml))
            {
                DateTime dt1     = DateTime.Now;
                string   pattern = "<td>\\d+\\.\\d+\\.\\d+\\.\\d+([\\s\\S])*?<div";
                if (Regex.IsMatch(strHtml, pattern))
                {
                    int i = 0;
                    foreach (Match m in Regex.Matches(strHtml, pattern))
                    {
                        ProxyIP myproxy    = new ProxyIP();
                        string  strContent = m.ToString();
                        pattern = "\\d+\\.\\d+\\.\\d+\\.\\d+";
                        if (Regex.IsMatch(strContent, pattern))
                        {
                            myproxy.IP = Regex.Match(strContent, pattern).ToString();
                        }
                        pattern = "<td>(\\d){2,4}</td>";
                        if (Regex.IsMatch(strContent, pattern))
                        {
                            string strPort = Regex.Match(strContent, pattern).ToString();
                            strPort      = strPort.Replace("<td>", "");
                            myproxy.Port = strPort.Replace("</td>", "");
                        }
                        pattern = "<td>(\\D){2}(\\s){1}(\\D){0,4}</td>";
                        if (Regex.IsMatch(strContent, pattern))
                        {
                            string strPlace = Regex.Match(strContent, pattern).ToString();
                            strPlace      = strPlace.Replace("<td>", "");
                            strPlace      = strPlace.Replace("</td>", "");
                            myproxy.Place = strPlace.Trim();
                        }
                        myproxy.Index = i.ToString();
                        myproxylist.Add(myproxy);
                        i++;
                        //myproxy.speed = mypro.ValidateProxy(myproxy.ip, myproxy.port).ToString();
                        string strOut = string.Format("NO.{0} IP:{1} Port:{2} Anonymity:{3} Place:{4} Speed:{5}", i, myproxy.IP, myproxy.Port, myproxy.Anonymity, myproxy.Place, myproxy.Speed);
                        Trace.WriteLine(strOut);
                    }
                    DateTime dt2 = DateTime.Now;
                    TimeSpan ts  = dt2 - dt1;

                    return("成功获取该网站数据,共获取" + myproxylist.Count.ToString() + "个匹配项,耗时" + ((long)ts.TotalMilliseconds).ToString() + "毫秒");
                }
                else
                {
                    return("连接网站成功,但数据内容不匹配!");
                }
            }
            else
            {
                return("网站连接超时,可能是您未连接互联网或者该网站无法打开!");
            }
        }
Пример #6
0
 public ProxyIP GetProxyIP()
 {
     lock ("ip")
     {
         if (oldProxyList.Count > 0)
         {
             ProxyIP p = oldProxyList[0];
             oldProxyList.RemoveAt(0);
             return(p);
         }
         else
         {
             return(null);
         }
     }
 }
Пример #7
0
        public string GetXiciFreeIP(List <ProxyIP> myproxylist, int kind)//正则匹配西刺的IP地址
        {
            string strHtml = "";

            switch (kind)
            {
            case 0:
                strHtml = GetWebHtml("http://www.xici.net.co/nn/");    //国内高匿
                break;

            case 1:
                strHtml = GetWebHtml("http://www.xici.net.co/nt/");    //国内普通
                break;

            case 2:
                strHtml = GetWebHtml("http://www.xici.net.co/wn/");    //国外高匿
                break;

            case 3:
                strHtml = GetWebHtml("http://www.xici.net.co/wt/");    //国外普通
                break;
            }
            if (!string.IsNullOrEmpty(strHtml))
            {
                string pattern = "<tr class=([\\s\\S])*?</tr>";
                if (Regex.IsMatch(strHtml, pattern))
                {
                    int      i   = 0;
                    DateTime dt1 = DateTime.Now;
                    foreach (Match m in Regex.Matches(strHtml, pattern))
                    {
                        ProxyIP myproxy    = new ProxyIP();
                        string  strContent = m.ToString();
                        pattern = "\\d+\\.\\d+\\.\\d+\\.\\d+";
                        if (Regex.IsMatch(strContent, pattern))
                        {
                            myproxy.IP = Regex.Match(strContent, pattern).ToString();
                        }
                        pattern = "<td>(\\d){2,4}</td>";
                        if (Regex.IsMatch(strContent, pattern))
                        {
                            string strPort = Regex.Match(strContent, pattern).ToString();
                            strPort      = strPort.Replace("<td>", "");
                            myproxy.Port = strPort.Replace("</td>", "");
                        }
                        pattern = "<td>[\\u4e00-\\u9fa5]{2}</td>";
                        if (Regex.IsMatch(strContent, pattern))
                        {
                            string strAnonymity = Regex.Match(strContent, pattern).ToString();
                            strAnonymity      = strAnonymity.Replace("<td>", "");
                            myproxy.Anonymity = strAnonymity.Replace("</td>", "");
                        }
                        if (kind == 2 || kind == 3)
                        {
                            pattern = "<td>\\s{1,}[\\S]{2,12}\\s{1,}</td>";
                            if (Regex.IsMatch(strContent, pattern))
                            {
                                string strPlace = Regex.Match(strContent, pattern).ToString();
                                strPlace      = strPlace.Replace("<td>", "");
                                strPlace      = strPlace.Replace("</td>", "");
                                myproxy.Place = strPlace.Trim();
                            }
                        }
                        else if (kind == 0 || kind == 1)
                        {
                            pattern = ">[\\u4e00-\\u9fa5]{2,10}</a>";
                            if (Regex.IsMatch(strContent, pattern))
                            {
                                string strPlace = Regex.Match(strContent, pattern).ToString();
                                strPlace      = strPlace.Replace(">", "");
                                strPlace      = strPlace.Replace("</a", "");
                                myproxy.Place = strPlace.Trim();
                            }
                        }
                        myproxy.Index = i.ToString();
                        myproxylist.Add(myproxy);
                        i++;
                        //myproxy.speed = mypro.ValidateProxy(myproxy.ip, myproxy.port).ToString();
                        string strOut = string.Format("NO.{0} IP:{1} Port:{2} Anonymity:{3} Place:{4} Speed:{5}", i, myproxy.IP, myproxy.Port, myproxy.Anonymity, myproxy.Place, myproxy.Speed);
                        Trace.WriteLine(strOut);
                    }
                    DateTime dt2 = DateTime.Now;
                    TimeSpan ts  = dt2 - dt1;

                    return("成功获取该网站数据,共获取" + myproxylist.Count.ToString() + "个匹配项,耗时" + ((long)ts.TotalMilliseconds).ToString() + "毫秒");
                }
                else
                {
                    return("连接网站成功,但数据内容不匹配!");
                }
            }
            else
            {
                return("网站连接超时,可能是您未连接互联网或者该网站无法打开!");
            }
        }