c# 快速验证代理IP是否有用

  1. public void yanzhen(string str, int port)  
  2.        {  
  3.            WebProxy proxyObject = new WebProxy(str, port);//str为IP地址 port为端口号  
  4.            HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://www.whatismyip.com.tw/");  
  5.            Req.Proxy = proxyObject; //设置代理   
  6.            HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();  
  7.            string str = "";  
  8.            string OkStr = "";  
  9.            Encoding code = Encoding.GetEncoding("UTF-8");  
  10.            using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), code))  
  11.            {  
  12.                if (sr != null)  
  13.                {  
  14.                    try  
  15.                    {  
  16.                        str = sr.ReadToEnd();  
  17.                        StringSub.substr(str, "<h2>""</h2>", 0);  
  18.                        str = str.Substring(str.IndexOf(start) + start.Length);  
  19.                        OkStr = str.Substring(0, str.IndexOf(last));  
  20.                        MessageBox.Show("验证成功!显示IP为" + OkStr);  
  21.                    }  
  22.                    catch  
  23.                    {  
  24.                        MessageBox.Show("文件读取失败!");  
  25.                    }  
  26.                    finally  
  27.                    {  
  28.                        sr.Close();  
  29.                    }  
  30.                }  
  31.            }  
  32.        }  

你可能感兴趣的:(c# 快速验证代理IP是否有用)